Need to Produce a different size matrix on each iteration
조회 수: 1 (최근 30일)
이전 댓글 표시
Good Morning,
I need your urgent help. I have a presentation on this in a few hours. I am trying to create one matrix concatenated to the previous per loop.
the concept is that the abc first matrix is [1 51]. the second matrix is [1 51;2 52]; the third matrix is [1 51;2 52;3 53]; and so on.
wqe=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
kli=[51;52;53;54;55;56;57;58;59;60;61;62;63;64;65];
hsd=size(kli,1);
kas=zeros(hsd,1);
sak=zeros(hsd,1);
abc=repmat({zeros(hsd,1)},hsd,1);
for i=1:hsd
kas(i)=wqe(i);
sak(i)=kli(i);
end
for h=2:1:hsd
abc{i}=[kas(i-1) sak(i-1);kas(i) sak(i)];
end
댓글 수: 0
채택된 답변
Alan Stevens
2021년 6월 28일
Try the following
wqe=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
kli=[51;52;53;54;55;56;57;58;59;60;61;62;63;64;65];
hsd=size(kli,1);
kas=zeros(hsd,1);
sak=zeros(hsd,1);
abc=zeros(hsd,2);
for i=1:hsd
kas(i)=wqe(i);
sak(i)=kli(i);
end
abc(1,:) = [kas(1) sak(1)];
for h=2:1:hsd
abc(h,:)=[kas(h) sak(h)];
end
disp(abc)
댓글 수: 3
Alan Stevens
2021년 6월 28일
More like this?
wqe=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
kli=[51;52;53;54;55;56;57;58;59;60;61;62;63;64;65];
hsd=size(kli,1);
kas=zeros(hsd,1);
sak=zeros(hsd,1);
abc=zeros(hsd,2);
for i=1:hsd
kas(i)=wqe(i);
sak(i)=kli(i);
end
abc(1,:) = [kas(1) sak(1)];
for h=2:1:hsd
abc(h,:)=[kas(h) sak(h)];
end
matrix{1}=abc(1,:);
for i = 2:hsd
matrix{i}=abc(1:i,:);
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!