How do I combine matrices in a specific order?

1 回表示 (過去 30 日間)
Yun Inn
Yun Inn 2013 年 4 月 4 日
for j=1:5
k=num2str(j); extension='.asc';
filename=strcat('Image',k,extension)
[Profiles]=readProfiles(filename); % Read profiles
ProfilesALL(:,j)=Profiles;
end
ProfISO_2_5=(ProfilesALL(:,1)+ProfilesALL(:,2))/2;
ProfISO_7_5=(ProfilesALL(:,2)+ProfilesALL(:,3))/2;
ProfISO_15=(ProfilesALL(:,3)+ProfilesALL(:,4))/2;
ProfISO_25=(ProfilesALL(:,4)+ProfilesALL(:,5))/2;
How do I occupy a new matrix, A, to be in this order:
A(:,1)=ProfilesALL(:,1);
A(:,2)=ProfISO_2_5;
A(:,3)=ProfilesALL:,2);
A(:,4)=ProfISO_7_5;
A(:,5)=ProfilesALL(:,3);
A(:,6)=ProfISO_15;
A(:,7)=ProfilesALL(:,4);
A(:,8)=ProfISO_25;
A(:,9)=ProfilesALL(:,5);
  3 件のコメント
Jan
Jan 2013 年 4 月 4 日
A vote for Matt's answer, although it is hidden in the comment section.
Yun Inn
Yun Inn 2013 年 4 月 4 日
Thank you!

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

採用された回答

Jan
Jan 2013 年 4 月 4 日
編集済み: Jan 2013 年 4 月 4 日
This procedure is actually a linear interpolation:
A = interp1(1:5, transpose(ProfilesALL), 1:0.5:5);
I cannot test this currently, such that I'm not sure about the transpose().
This is a leaner method to create the file name:
filename = sprintf('Image%d.asc', k);
Letting an array gorw iteratively wastes time, but I do not think that this can be measured for the small number of 5 loops. Nevertheless, I suggest to pre-allocate in general. Either allocate ProfilesALL at once by zeros(), when you know the size at the beginning. Or perform an implicit allocation by inserting the last element at first:
for j = 5:-1:1
...

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by