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

7 次查看(过去 30 天)
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