Time Varying Input in Matrix
9 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Star Strider
on 22 Apr 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.)
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!