Problem with plot command in a for loop!
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2016년 3월 22일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!