Plot a graph with linspace

116 visualizzazioni (ultimi 30 giorni)
Kebels3
Kebels3 il 7 Gen 2021
Risposto: Daniel Pollard il 7 Gen 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)

Risposta accettata

Daniel Pollard
Daniel Pollard il 7 Gen 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.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by