Effacer les filtres
Effacer les filtres

How to draw a line in if condition and plotting

1 vue (au cours des 30 derniers jours)
Meva
Meva le 29 Déc 2015
Commenté : Meva le 4 Jan 2016
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?

Réponse acceptée

Vineeth Kartha
Vineeth Kartha le 4 Jan 2016
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 commentaire
Meva
Meva le 4 Jan 2016
Thanks I have figured the problem out.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by