Time Varying Input in Matrix

9 views (last 30 days)
Ian Smith
Ian Smith on 22 Apr 2016
Edited: Ian Smith on 23 Apr 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

Accepted Answer

Star Strider
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.)
  2 Comments
Ian Smith
Ian Smith on 22 Apr 2016
perfect thank you very much

Sign in to comment.

More Answers (0)

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!