How to draw a line in if condition and plotting

2 次查看(过去 30 天)
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by