Problem with plot command in a for loop!
1 view (last 30 days)
Show older comments
Hi there,
I've written a code which finally gives me an array, A. The code works fine and gives me the array correctly, but the problem is that I cannot plot it (I'm not sure if I should use plot command in the loop)! Could anybody help me with that please? Here is the code:
clear all
clc
i=0;
for t=0.05:0.05:10
i=i+1;
ksi=5;
m=1;
wn=2*pi/t;
k=wn^2*m;
U0=0;
V0=0;
dt=0.005;
ag=load('BamL.txt');
g=32.2;
NBL(ksi,m,k,U0,V0,dt,ag,g);
D(i,1)=max(ans(:,1));
V(i,1)=D(i,1)*wn;
A(i,1)=D(i,1)*wn^2;
end
figure
plot(t, A, 'r');
xlabel('Period');
ylabel('Accel');
0 Comments
Accepted Answer
Walter Roberson
on 22 Mar 2016
After the for loop, your loop control variable t is going to keep its final value. When you get to the plot() call it is going to be a scalar. You need to duplicate the vector you listed in your for loop or you need to record each t value as you go through the loop and use that recorded value.
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!