Filter löschen
Filter löschen

Processing data from multiple files

2 Ansichten (letzte 30 Tage)
Dolev
Dolev am 5 Apr. 2023
Bearbeitet: Stephen23 am 5 Apr. 2023
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
app.filenamelsr are cells containing the file names. for example
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

Akzeptierte Antwort

Stephen23
Stephen23 am 5 Apr. 2023
Bearbeitet: Stephen23 am 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
  2 Kommentare
Dolev
Dolev am 5 Apr. 2023
Bearbeitet: Dolev am 5 Apr. 2023
thank you very much, this will work for multiple files?
Stephen23
Stephen23 am 5 Apr. 2023
Bearbeitet: Stephen23 am 5 Apr. 2023
"thank you very much, this will work for multiple files?"
Of course, that is exactly what the loop is for. See also:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Ergin Sezgin
Ergin Sezgin am 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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by