How can I merge the matrices that produce different dimensions in the loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (3)
KALYAN ACHARJYA
am 11 Dez. 2022
Bearbeitet: KALYAN ACHARJYA
am 11 Dez. 2022
#Example
data_store=cell(5,1)
for i=1:5
data=rand(i,3)
data_store{i}=data;
end
dat=cell2mat(data_store)
0 Kommentare
VBBV
am 11 Dez. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!