Time Varying Input in Matrix
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ian Smith
el 22 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
0 comentarios
Respuesta aceptada
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!