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

1 view (last 30 days)
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);
q and w have different size in each iteration

Accepted Answer

Yongjian Feng
Yongjian Feng on 27 Oct 2021
Do you know the max size? Can you initialize the max size to all 0s?
Yongjian Feng
Yongjian Feng on 27 Oct 2021
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.

Sign in to comment.

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by