Processing data from multiple files
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello
i have written a code for a standalone app in the app desginer that supposed to read number of excel files and process the data from them
this part of the code is responsible to read the data and assign it to variables.
[app.filenamelsr,pathname] = uigetfile({'*.xls';'*.xlsx'},MultiSelect="on");
app.C=iscell(app.filenamelsr(1,2));
if app.C==1
app.Lengthlsr=length(app.filenamelsr);
else
app.Lengthlsr=1;
end
for i=1:length(app.filenamelsr)
LSR(i)=xlsread(fullfile(pathname,app.filenamelsr{1,i}));
app.t_lsr(i)=LSR(i,:,1);
app.S(i)=LSR(i,:,2);
app.r(i)=LSR(i,:,3);
app.dt(i)=LSR(i,:,4);
app.t_k(i)=app.t_lsr(i)+273;
app.R_r(i)=app.r(i).*(10^(5));
end
but when i try to run it i get this error
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1346399/image.png)
app.filenamelsr are cells containing the file names. for example
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1346404/image.png)
my logic is that in order to use the first name the indices should be {1,1} and for the second {1,2} so forth. therefore for the loop it should be like that {1,i}
what did i do wrong? assume at least 2 files are loaded
thanks for the help
0 Commenti
Risposta accettata
Stephen23
il 5 Apr 2023
Modificato: Stephen23
il 5 Apr 2023
"what did i do wrong?"
You tried to assign an array into a scalar location. Some of the other indexing will not work either, for the same reason. You could avoid this by using lots of comtainer arrays or to preallocate arrays of the correct sizes and then use (non-scalar) indexing. That would work... if you like doing things in a complex way.
A simpler approach is to just store the entire matrix for each file in one cell array, then concatenate them after the loop:
[C,P] = uigetfile({'*.xls';'*.xlsx'},MultiSelect="on");
C = cellstr(C); % simpler way of handling one file
D = cell(size(C));
for k = 1:numel(C)
F = fullfile(P,C{k});
D{k} = readmatrix(F);
end
LSR = cat(3,D{k})
... do whatever with that array
Più risposte (1)
Ergin Sezgin
il 5 Apr 2023
Hi Dolev,
Try using curly brackets "{}" instead of parentheses. Alternatively, take a look at datastore which is another option for importing and managing data collections.
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!