Hi, I would like to save a vector (size change at every loop) in a matrix

조회 수: 10 (최근 30일)
RogerLM
RogerLM 2016년 6월 23일
댓글: RogerLM 2016년 6월 23일
I would like to divide a vector in many vectors and put all of them in a matrix. I got this error "Subscripted assignment dimension mismatch."
STEP = zeros(50,1);
STEPS = zeros(50,length(locate));
for i = 1:(length(locate)-1)
STEP = filtered(locate(i):locate(i+1));
STEPS(:,i) = STEP;
end
I take the value of "filtered" from (1:50) at the first time for example and I would like to stock it in the first row of a matrix, then for iterations 2, I take value of "filtered from(50:70) for example and I stock it in row 2 in the matrix, and this until the end of the loop..
If someone has an idea, I don't get it! Thank you!

답변 (1개)

Jos (10584)
Jos (10584) 2016년 6월 23일
Vectors with different sizes cannot be stacked into a single array. You can, for instance, use cell arrays as an alternative.
C = cell(5,1) ;
for k=1:5,
C{k} = 1:k ; % vectors with different sizes on each iteration
end

카테고리

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