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!