How to plot a continuous graph as shown in the below graph?

16 vues (au cours des 30 derniers jours)
siet ece
siet ece le 1 Juin 2023
Commenté : siet ece le 1 Juin 2023
  7 commentaires
Dyuman Joshi
Dyuman Joshi le 1 Juin 2023
How did you generate this graph?
siet ece
siet ece le 1 Juin 2023
By manually generating the nodes, but i couldn't connect the node as a continuous plot
grid on
for t=1:6;
y=1;
plot(t,y,'o');
hold on
for t1=6:7;
y1=0.45;
plot(t1,y1,'o')
hold on
for t2=7:8;
y2=1;
plot(t2,y2,'o');
hold on
for t3=8:9;
y3=0.4;
plot(t3,y3,'o');
hold on
for t4=9:11;
y4=0.25;
plot(t4,y4,'o');
hold on
for t5=11:18;
y5=0.41;
plot(t5,y5,'o');
hold on
for t6=18:19;
y6=0.5;
plot(t6,y6,'o');
hold on
for t7=19:20;
y7=0.68;
plot(t7,y7,'o');
hold on
for t8=20:21;
y8=0.2;
plot(t8,y8,'o');
hold on
for t9=21:24;
y9=0.75;
plot(t9,y9,'o');
end
end
end
end
end
end
end
end
end
end

Connectez-vous pour commenter.

Réponse acceptée

Pratham Shah
Pratham Shah le 1 Juin 2023
After analyzing your code, I think you are on totally wrong path. There is no need of using 'for' or 'hold on' to plot point in graph. You can simply plot X and Y after making 2 vectors of X and Y.
x=[1:6 6:7 7:8 8:9 9:11 11:18 18:19 19:20 20:21 21:24];
y=[ones(1,6) 0.45.*ones(1,2) ones(1,2) 0.4.*ones(1,2) 0.25.*ones(1,3) 0.41.*ones(1,8) 0.5.*ones(1,2) 0.68.*ones(1,2) 0.2.*ones(1,2) 0.75.*ones(1,4)];
plot(x,y)
grid on
xlim([0 25])
ylim([0 1.2])
Try it!
Hope this helps :)

Plus de réponses (1)

Torsten
Torsten le 1 Juin 2023
Modifié(e) : Torsten le 1 Juin 2023
t1 = [1 6]; y1 = [1 1];
t2 = [6 7]; y2 = [0.45 0.45];
t3 = [7 8]; y3 = [1 1];
t4 = [8 9]; y4 = [0.4 0.4];
t5 = [9 11]; y5 = [0.25 0.25];
t6 = [11 18]; y6 = [0.41 0.41];
t7 = [18 19]; y7 = [0.5 0.5];
t8 = [19 20]; y8 = [0.68 0.68];
t9 = [20 21]; y9 = [0.2 0.2];
t10 = [21 24]; y10 = [0.75 0.75];
t = [t1,t2,t3,t4,t5,t6,t7,t8,t9,t10];
y = [y1,y2,y3,y4,y5,y6,y7,y8,y9,y10];
plot(t,y)
xlim([0 25])
ylim([0 1.2])

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by