Processing data from multiple files
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
更多回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!