Time Varying Input in Matrix

8 vues (au cours des 30 derniers jours)
Ian Smith
Ian Smith le 22 Avr 2016
Modifié(e) : Ian Smith le 23 Avr 2016
I have a time varying input, K.
A= [0; 0; K];
B= [5 -3 2; 2 -3 1; 3 2 1];
for x=1:length(t)
A= [0; 0; K];
B= [5 -3 2; 2 -3 1; 3 2 1];
C = linsolve(B, A);
end
I am getting the error that the answer changes size every loop iteration how can I solve this. Thanks

Réponse acceptée

Star Strider
Star Strider le 22 Avr 2016
‘I am getting the error that Icell(x) changes size every loop iteration how can i solve this.’
That’s just a warning, not an error.
The way to prevent it is to ‘preallocate’ ‘Icell’ before the loop. One way to do this is:
Icell = nan(1, length(t));
This will create a row vector of NaN values that your ‘Icell’ assignment just has to fill, rather than creating a new value for it with each iteration. (Other options in addition to nan are zeros and inf. All will create the vector you want, the only difference being the values it fills them with.)
  2 commentaires
Ian Smith
Ian Smith le 22 Avr 2016
perfect thank you very much
Star Strider
Star Strider le 22 Avr 2016
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