Plot a graph with linspace

117 Ansichten (letzte 30 Tage)
Kebels3
Kebels3 am 7 Jan. 2021
Beantwortet: Daniel Pollard am 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)

Akzeptierte Antwort

Daniel Pollard
Daniel Pollard am 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.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by