フィルターのクリア

Problem with plot command in a for loop!

1 回表示 (過去 30 日間)
Antonio
Antonio 2016 年 3 月 22 日
コメント済み: Antonio 2016 年 3 月 25 日
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');

採用された回答

Walter Roberson
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.
  1 件のコメント
Antonio
Antonio 2016 年 3 月 25 日
Thanks Walter

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by