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

3 vues (au cours des 30 derniers jours)
RogerLM
RogerLM le 23 Juin 2016
Commenté : RogerLM le 23 Juin 2016
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!

Réponses (1)

Jos (10584)
Jos (10584) le 23 Juin 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
end

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by