GUI-import and process multiple files

9 visualizzazioni (ultimi 30 giorni)
ChyaYan Liaw
ChyaYan Liaw il 31 Mar 2017
Modificato: ChyaYan Liaw il 31 Mar 2017
I've created two radio buttons. I want to make that only one file is imported when one button is selected and multiple files are imported when the other button (handles.rbmultiple) is selected. Right now I was able to import one file, update axes, and fit different sections of the curve (shown in the video: https://goo.gl/7ny46h ). But I don't really know how to import multiple files, plot the curves on the same graph, and do the fitting. I got errors after adding the for loop. Any help will be highly appreciated! The full code can be found here: https://github.com/dupypy/MechanicalGUI/blob/master/gui.m
Part of the code is
plotstyle = get(handles.rbmultiple, 'value');
if plotstyle
[filenames] = uigetfile('*.csv','MultiSelect','on');
numfiles = size(filenames,2);
for k = 1:numfiles
handles.filename = filenames(k);
handles.filename
guidata(hObject, handles);
setPopupMenuString(handles.popupmenuX, eventdata, handles); % custom function
setPopupMenuString(handles.popupmenuY, eventdata, handles); % custom function
set(handles.popupmenuX, 'callback', 'gui(''updateAxes'',gcbo, [], guidata(gcbo))');
set(handles.popupmenuY, 'callback', 'gui(''updateAxes'',gcbo, [], guidata(gcbo))');
end
else
handles.filename = uigetfile('*.csv');
guidata(hObject, handles);
setPopupMenuString(handles.popupmenuX, eventdata, handles); % custom function
setPopupMenuString(handles.popupmenuY, eventdata, handles); % custom function
set(handles.popupmenuX, 'callback', 'gui(''updateAxes'',gcbo, [], guidata(gcbo))');
set(handles.popupmenuY, 'callback', 'gui(''updateAxes'',gcbo, [], guidata(gcbo))');
end

Risposte (1)

Jan
Jan il 31 Mar 2017
Modificato: Jan il 31 Mar 2017
filenames is a cell string, such that you need curly braces to get a single file name.
Using the path name is more convenient and safer.
[filenames, pathname] = uigetfile('*.csv','MultiSelect','on');
numfiles = size(filenames, 2);
for k = 1:numfiles
handles.filename = fullfile(pathname, filenames{k});
...
Whenever you mention in the forum, that you get an error message, add a complete copy of the message. It is easier to suggest a solution than to guess the problem and you have the required details on your screen already.
The contents of the loop performs the same commands in each iteration. I assume you want to apply some settings, which depend on the filename?
  2 Commenti
ChyaYan Liaw
ChyaYan Liaw il 31 Mar 2017
Yes, it solves the problem now. I got an error message saying "Cell contents reference from a non-cell array object" before. However, I still only got one file plotted on the graph when I use the following code. I wanted to import different files and plot different curves on the same graph, and do linear fit on different sections of the curves. I don't really know how to tackle this problem...
for k = 1:numfiles
handles.filename = fullfile(pathname, filenames{k});
%handles.filename = filenames(k);
guidata(hObject, handles);
setPopupMenuString(handles.popupmenuX, eventdata, handles); % custom function
setPopupMenuString(handles.popupmenuY, eventdata, handles); % custom function
set(handles.popupmenuX, 'callback', 'gui(''updateAxes'',gcbo, [], guidata(gcbo))');
set(handles.popupmenuY, 'callback', 'gui(''updateAxes'',gcbo, [], guidata(gcbo))');
end
ChyaYan Liaw
ChyaYan Liaw il 31 Mar 2017
Modificato: ChyaYan Liaw il 31 Mar 2017
I just wanted to be a little bit more clear. What I wanted to do is to first select a file and plot it, and while using the same x and y parameters, I can load more files(one file at a time) and plot the curves on the same graph. If I want to load the files one by one, maybe I should not set multiselect to on, right? I think it is very complicated and I am not quite sure how to start.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by