Problem with plot command in a for loop!
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Antonio
am 22 Mär. 2016
Kommentiert: Antonio
am 25 Mär. 2016
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 22 Mär. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!