How to draw a line in if condition and plotting

2 ビュー (過去 30 日間)
Meva
Meva 2015 年 12 月 29 日
コメント済み: Meva 2016 年 1 月 4 日
Hello,
My code is:
dx=0.01;
x=0:0.01:1;
dt=0.0001;
for nt=1:10001
t=(nt-1)*dt
...
if t==0
divider(:) = NaN;
end
if t>0 && t <=0.01
divider(1) = 0.25;
for i=2:ii
divider(i) = NaN;
end
end
if t>0.1 && t <=0.02
divider(1) = 0.25; divider(2) = 0.25;
for i=3:ii
divider(i) = NaN;
end
end
if t >=0.03
divider(:) = 0.25;
end
plot(x,divider,'g','Linewidth',4.4);
end
I want to see the divider in t=0, t=0.01, t=0.02,.. and it must be a horizontal line changing with time. It should be increased gradually with x axis. But it is not. How can I draw it pls?

採用された回答

Vineeth Kartha
Vineeth Kartha 2016 年 1 月 4 日
Hi,
In the code that you have provided above, the variable 'ii' is undefined. It is a good practice to predefine the variable 'divider', Add the line provided below before the for loop begins.
divider=zeros(1,length(x));
In the last if condition: As per the code provided I can see that the variable 'divider' has only 0.25 as the value and this will plot only a straight line 0.25. Please provide more information on the output that you are expecting. Also please post a sample image of the output that you are expecting.
  1 件のコメント
Meva
Meva 2016 年 1 月 4 日
Thanks I have figured the problem out.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by