How to use the cat function for a sequence of arrays?

3 ビュー (過去 30 日間)
Sam
Sam 2019 年 3 月 2 日
コメント済み: madhan ravi 2019 年 3 月 2 日
I need to find the mean of 1800 arrays, size 421x561. I am currently just working with 3 of them, until I figure out the method. The arrays are named ir_U20_h15_RD_5853, ir_U20_h15_RD_5854, etc. (sequentially). I am trying to combine all the arrays into one 3D array, so I can take the mean of that. I tried the cat function, which is working just fine for the 3 files that I'm using right now, but how do I use it without listing out the names of 1800 arrays?
%to load multiple files%
for k = 5853:5855
filename = sprintf('ir_U20_h15_RD_%d.dat',k);
fullname1 = fullfile('C:\Users\sc56\Documents\CEE 498 EHO\A2\IR Dats\', filename);
load(fullname1);
end
%to combine the files into a single array%
C = cat(3, ir_U20_h15_RD_5853, ir_U20_h15_RD_5854, ir_U20_h15_RD_5855);

回答 (1 件)

madhan ravi
madhan ravi 2019 年 3 月 2 日
When your loading the file inside the loop save it in the third dimension within the loop.
  2 件のコメント
Sam
Sam 2019 年 3 月 2 日
Thanks for your help. I'm unsure how to do that. This is where I'm at:
%to load multiple files%
for k = 5853:5855
filename = sprintf('ir_U20_h15_RD_%d.dat',k);
fullname1 = fullfile('C:\Users\sc56\Documents\CEE 498 EHO\A2\IR Dats\', filename);
C(:,:,k)= load(fullname1);
end
but I get this error:
Unable to perform assignment because the size of the left side is 1-by-1 and the size
of the right side is 421-by-561.
madhan ravi
madhan ravi 2019 年 3 月 2 日
C=zeros(421,561,numel(5853:5855)); % add this before the loop

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by