Show older comments
sample1=[1 2 3; 1 2 3; 1 2 3]
sample2=[2 2 3]
sample3=[6 2 3; 2 2 3]
・
・
・
sample(n)=[5 2 3; 2 1 3; 2 7 3]
のような配列名に規則性があり、配列がM行×3列の配列同士を垂直を方向に連結するにはどうしたらよいですか。
(配列数nは50くらいの設定で。)
Accepted Answer
More Answers (1)
Hernia Baby
on 2 Mar 2021
あまりお勧めではないですが、eval関数を使ってください
clear
% 最初のデータ
sample1=[1 2 3; 1 2 3; 1 2 3];
sample2=[2 2 3];
sample3=[6 2 3; 2 2 3];
sample4=[5 2 3; 2 1 3; 2 7 3];
% ワークスペースの変数の数をカウント
l = length(who);
% 垂直に文字を連結
s = [];
for i = 1:l
eval(sprintf('s = vertcat(s,sample%i);',i));
end
% 確認
s
s =
1 2 3
1 2 3
1 2 3
2 2 3
6 2 3
2 2 3
5 2 3
2 1 3
2 7 3
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!