Time Varying Input in Matrix

6 visualizaciones (últimos 30 días)
Ian Smith
Ian Smith el 22 de Abr. de 2016
Editada: Ian Smith el 23 de Abr. de 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

Respuesta aceptada

Star Strider
Star Strider el 22 de Abr. de 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 comentarios
Ian Smith
Ian Smith el 22 de Abr. de 2016
perfect thank you very much
Star Strider
Star Strider el 22 de Abr. de 2016
My pleasure.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by