How can I fill a big matrix when I have small matrices with different sizes in each iteration?

조회 수: 4 (최근 30일)
Hello guys. I have some lines of codes in which I have a for loop. In for loop I have to fill a big matrix by some small matrices but with different size. How can I do that?
for i=1:n
[q,w] = function(i);
s1(:,k)=q;
s1(:,k+1)=w;
k=k+2;
end
q and w have different size in each iteration

채택된 답변

Yongjian Feng
Yongjian Feng 2021년 10월 27일
Do you know the max size? Can you initialize the max size to all 0s?
  댓글 수: 2
Ashkan Rigi
Ashkan Rigi 2021년 10월 27일
Yes. maybe I can understand the max size. I will be thankful if you write answer for both knowing the max size and not knowing the max size
Yongjian Feng
Yongjian Feng 2021년 10월 27일
Might not be easy if you don't know the max size in advance.
Not sure about the best approach. Maybe you can
  1. Start with a best estimated max size.
  2. Each iteration in the for loop, check if your best estimate is still true. If true, everything is good.
  3. If not true, then you need to adjust to a bigger max, and then copy over.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by