Plot a graph with linspace

120 vues (au cours des 30 derniers jours)
Kebels3 le 7 Jan 2021
Hi guys,
I want to plot this graph with Linspace,
This is what i got;
t = linspace(0,3,4)
u = [1 1 0 0]
plot(t,u)
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Réponse acceptée

Daniel Pollard le 7 Jan 2021
You can't get that exact plot with linspace. I've managed to get it by using
t = [0 1 1 2 3];
u = [1 1 0 0 0];
plot(t, u, 'k-')
which gets the plot you want. To make the plot exactly you need to have two u values for t=1, hence the way I defined it. Linspace assigns one value to each position, so you won't get the vertical line you want.
You could make an approximation by using lots of values - something like
t = linspace(0, 3, 1000);
u = (t < = 1);
plot(t, u, 'k-')
I've used 1000 data points, the more you use the closer it will appear to what you want.
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by