Load multiple data and put in a list box with app designer

조회 수: 5 (최근 30일)
acegi bdegi
acegi bdegi 2017년 11월 7일
Hello all,
I want to load multiple files using a button, and display the filenames in a list box, using app designer. Further in the GUI, I want to be able to recall specific files in this list box to use their data for plotting or calculating for example.
To do this, I use a button called 'Load Files'. This button says:
filename = uigetfile('*.m','Select the MATLAB code files', 'MultiSelect', 'on');
varlist = who('-file',filename);
app.DataOutput.Items = varlist(1);
The error I get here is 'Error using who. Argument must contain a string'. What's going wrong here?
EDITED (11/9/2017): What I have now is: (where app.DataOutput is the listbox)
filename = uigetfile('*.m','Select the MATLAB code files', 'MultiSelect', 'on');
for i = 1:length(filename)
varlist = who('-file',filename{i})
app.DataOutput.Items(i) = varlist(1)
end
It now puts all the files in the list box. But the problem here is that it is not loading the data of these files in the workspace. (I need the data from these files to be called later in the GUI to do calculations and plots with)
The next step is to only use the data from the selected files in the list box. So, let's say I have loaded six files in the list box. I first plot all these data in a figure which gives me six line graphs in one UIaxes. After seeing these plots, I'm only interested in the first three plots. So I select the first three filenames in the list box (and press a button) so only the data of these files are being used for plotting now.
Is it possible, for example, to have a command in app designer that loads data from a chosen folder in the workspace under a name that is given in a loop? For example, I load six files in app designer, using uigetfile. These files have different names, let's say: 'vibrationdata01', 'vibrationdata02', 'shockdata01', 'shockdata02', 'initialstate' and 'endstate'. If I could give these data a variable name, it would be easier to call these data later in the app designer. Easiest would be: a = 'filename 1'..... n = 'filename n'.
Is this possible to do with app designer?
  댓글 수: 4
Greg
Greg 2017년 11월 9일
for i = 1:length(filename)
varlist = who('-file',filename{1})
app.DataOutput.Items(i) = varlist(1)
end
Not sure how this is working for you, you're repeatedly inspecting the first file.
As for getting to the actual data (not just filenames and variable names), did you try the load function?
acegi bdegi
acegi bdegi 2017년 11월 13일
That's a mistake, I meant filename{i}. Changed in topic, tnx for noticing.
I have tried the command
uiopen('load')
But the problem here is that it doesn't give me the opportunity to open multiple files and
x = uiopen('load')
is not a valid command, so I cannot call specific files later in my GUI, having a random filename. If I just use uiopen('load'), (which opens the folder as well) and select a .mat file which contains data, it doesn't load the data in my MATLAB workspace, but instead, it saves it somewhere I don't know. If I plot the data, using the known names for the data, it plots in the graph very well.
uiopen('load')
plot(app.TimeGraph, data_01_x, data_01_y)
But I don't want to use the data names in my code view, because I want to load different data each time. It has to be a variable.

댓글을 달려면 로그인하십시오.

답변 (1개)

120017001 SoME AEROSPACE AAKHASH SUNDARESAN
% You can use the MATLAB's datastore function instead of using the who function
ds=datastore("Directory Path");
% Use a for loop and read all the files
files={}; % Initialize a null cell array
for i=1:1:length(ds.Files)
files{i}=read(ds);
end

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by