How can I fill a big matrix when I have small matrices with different sizes in each iteration?
1 次查看(过去 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
0 个评论
采纳的回答
Yongjian Feng
2021-10-27
Do you know the max size? Can you initialize the max size to all 0s?
2 个评论
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
- Start with a best estimated max size.
- Each iteration in the for loop, check if your best estimate is still true. If true, everything is good.
- If not true, then you need to adjust to a bigger max, and then copy over.
更多回答(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!