Plot a graph with linspace

119 visualizaciones (últimos 30 días)
Kebels3
Kebels3 el 7 de En. de 2021
Respondida: Daniel Pollard el 7 de En. de 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)

Respuesta aceptada

Daniel Pollard
Daniel Pollard el 7 de En. de 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.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by