How can I merge the matrices that produce different dimensions in the loop
1 回表示 (過去 30 日間)
古いコメントを表示
Suppose my loop will generate matrices of different dimensions such as the first five matrices
first lap
28.984 30 58.984
28.984 13.943 42.927
28.984 30.082 59.066
28.984 14.959 43.943
28.984 44.025 73.009
2
30 13.943 43.943
30 0.041 30.041
30 27.968 57.968
30 29.066 59.066
30 27.424 57.424
30 57.968 87.968
3
28.44 29.528 57.968
28.44 30.544 58.984
28.44 57.968 86.408
4
15.041 57.968 73.009
15.041 44.025 59.066
15.041 73.009 88.05
5
13.943 30.082 44.025
13.943 0.082 14.025
I want to combine the variables generated in each loop
ex.
28.984 30 58.984
28.984 13.943 42.927
28.984 30.082 59.066
28.984 14.959 43.943
28.984 44.025 73.009
30 13.943 43.943
30 0.041 30.041
30 27.968 57.968
30 29.066 59.066
30 27.424 57.424
30 57.968 87.968
28.44 29.528 57.968
28.44 30.544 58.984
28.44 57.968 86.408
15.041 57.968 73.009
15.041 44.025 59.066
15.041 73.009 88.05
13.943 30.082 44.025
13.943 0.082 14.025
I tried writing directly into a new variable, but each time the length is different and it is overwritten
0 件のコメント
回答 (3 件)
KALYAN ACHARJYA
2022 年 12 月 11 日
編集済み: KALYAN ACHARJYA
2022 年 12 月 11 日
#Example
data_store=cell(5,1)
for i=1:5
data=rand(i,3)
data_store{i}=data;
end
dat=cell2mat(data_store)
0 件のコメント
VBBV
2022 年 12 月 11 日
Use [ ] inside the loop
for k = 1:10
A = rand(5,3);
B = rand(6,3);
C = rand(3,3);
D = rand(2,3);
Merge(:,:,k) = [A;B;C;D];
end
Merge % combined values as matrix
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!