Clear Filters
Clear Filters

how to save all iteration output to plot graph later ?

2 views (last 30 days)
I have 21 matrices outputs from a for loop of matrix size 21X21. i want to extract first row of all matrix from the output for each iteration and save it later to plot graph. when i plot graph, only the final output is plotted and not all the iteration output.when i save the output by indexing it says subscript mismatch error. can anyone help me how to index the bending output and get it later for plotting.
for i = 1:21
delP = P0+a*vel(:,i)+b*accl(:,i);
delu = Kcap\delP;
delv = a1*delu-a4*vel(:,i)-a6*accl(:,i) ;
dela = a2*delu-a3*vel(:,i)-a5*accl(:,i);
depl(:,i+1) = depl(:,i)+delu ;
bending(i) = depl(1,:);

Answers (1)

dpb on 25 Aug 2019
In bending(i) = depl(1,:); you don't have but one index dimension on LHS in which you're trying to store a vector...
Before the loop define/preallocate
bending=zeros(21); % creates square array of zeros for later
for i=1:21
bending(i,:)=depl(1,:); % save first row to array
I would strongly recommend to move the "magic number" 21 out of the explicit use as a constant and to use the size function to determine the limits. Then you can generalize the code and not have to make edit changes by hand should you decide to change the dimensions.
Shabnam Sulthana Mohamed Isaque
I changed the code but still i am getting the error in bending (i,:) as Assignment has more non-singleton rhs dimensions than non-singleton subscripts.
dpb on 25 Aug 2019
Let's see what you changed it to and the complete error in context...cut and paste all the red text; don't try to paraphrase.
Looks like what I wrote should work just fine if what you have matches what you posted.
Altho never hurt to set a breakpoint at that line and then from the command window show us what
whos depl
But, that aside
depl(:,i+1) = depl(:,i)+delu ;
will actually create 22 columns for depl when i=21 so the size of the second dimension of the bending array should be 22, not 21.
Also, we don't actually know what size(vel,1) returns, so that there are only 21 rows was an unjustified assumption--the array needs to be that long.
But, that's a dimensions error, not number of non-singleton dimensions error so something else isn't as it seems.

Sign in to comment.


Find more on 2-D and 3-D Plots 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!