How can I save vector values that changes its size each iteration?

I have the following type of code:
while i<10
i=i+1;
while ...
C=...
end
B(i,:)=C;
end
where C is 1-row vector and B is supposed to be 10-row matrix with each row equal to C from iterations 1:10. The problem is that C changes its size each iteration and I am not sure how to save all its values in form of a matrix.

댓글 수: 2

Can you share all of your code?
Here is an example:
while i<10
i=i+1;
C=1:i;
B(i,:)=C;
end

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

 채택된 답변

Stephen23
Stephen23 2018년 3월 2일
편집: Stephen23 2018년 3월 2일
N = 10;
B = nan(N,N);
for k = 1:N
B(k,1:k) = 1:k;
end
Or use a cell array.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 3월 2일

댓글:

2018년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by