Problem with plot command in a for loop!
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Antonio
el 22 de Mzo. de 2016
Comentada: Antonio
el 25 de Mzo. de 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 comentarios
Respuesta aceptada
Walter Roberson
el 22 de Mzo. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!