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

10 views (last 30 days)
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;
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!

Answers (1)

Jos (10584)
Jos (10584) on 23 Jun 2016
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


Find more on Matrices and Arrays 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!