Load multiple data and put in a list box with app designer
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
acegi bdegi
el 7 de Nov. de 2017
Respondida: 120017001 SoME AEROSPACE AAKHASH SUNDARESAN
el 4 de Sept. de 2020
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 comentarios
Greg
el 9 de Nov. de 2017
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?
Respuestas (1)
120017001 SoME AEROSPACE AAKHASH SUNDARESAN
el 4 de Sept. de 2020
% 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
0 comentarios
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!