필터 지우기
필터 지우기

Processing data from multiple files

조회 수: 2 (최근 30일)
Dolev
Dolev 2023년 4월 5일
편집: Stephen23 2023년 4월 5일
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

채택된 답변

Stephen23
Stephen23 2023년 4월 5일
편집: Stephen23 2023년 4월 5일
"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
Dolev
Dolev 2023년 4월 5일
편집: Dolev 2023년 4월 5일
thank you very much, this will work for multiple files?
Stephen23
Stephen23 2023년 4월 5일
편집: Stephen23 2023년 4월 5일
"thank you very much, this will work for multiple files?"
Of course, that is exactly what the loop is for. See also:

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

추가 답변 (1개)

Ergin Sezgin
Ergin Sezgin 2023년 4월 5일
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.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by