Effacer les filtres
Effacer les filtres

assign empty vector to an element of a vector in a for loop

4 vues (au cours des 30 derniers jours)
Shan  Chu
Shan Chu le 10 Juin 2019
Commenté : Star Strider le 10 Juin 2019
Hi everyone,
I created a 'for' loop with 'solve'
for i0=1:1:length(sig)
syms r
r0(i0)=double(solve(function_of_r,r));
end
At some points, the 'solve' function returns '0×1 empty double column vector' (which is correct).
But then, Matlab returns an error 'Unable to perform assignment because the left and right sides have a different number of elements.' because of the empty vector.
I understood the problem but is there any way to assign that empty vector to an element of another vector?
I would like to have the vector in the form like r=[1, 3 , 4 ,[], [], [],..., 5, 7,9]
Thanks

Réponse acceptée

Star Strider
Star Strider le 10 Juin 2019
One option could be to assign it instead as a cell array:
r0{i0} = ..
.Note the curly brackets {}.
  2 commentaires
Shan  Chu
Shan Chu le 10 Juin 2019
Thanks sir, It's what I need
Star Strider
Star Strider le 10 Juin 2019
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

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