How to plot a line over a specific interval?

17 visualizaciones (últimos 30 días)
Alexander Horton
Alexander Horton el 29 de Jun. de 2020
Comentada: Alexander Horton el 30 de Jun. de 2020
I am attempting to plot cubic splines for 5 points. I have 4 functions to match each segment, but I only want the interval of the line that applies to that segment to appear on my plot.
I have these four lines:
plot (x,g(1))
plot (x, g(2))
plot(x, g(3))
plot(x, g(4))
They appear as so:
This is correct, but i want g1 to ONLY show from -1 to -.5. g2 to ONLY show from -.5 to 0, etc.

Respuesta aceptada

the cyclist
the cyclist el 29 de Jun. de 2020
Editada: the cyclist el 29 de Jun. de 2020
Can you upload the data? Specifically, it is unclear to me what sort of data type g is.
Instead of plotting x, you'll want to do something like plotting
x(x>-1 & x<-0.5); % for g1
but I can't tell how to handle g1 without more info.
Also, it was unclear to me if the intervals are meant to be on x, or on g.
  3 comentarios
the cyclist
the cyclist el 29 de Jun. de 2020
Yes, I edited it. Thanks.
Alexander Horton
Alexander Horton el 30 de Jun. de 2020
I ended up figuring everything out. I ended up using fplot, which let me put in an interval to show as an input.
fplot (@(x) (a(2).*(x-z(2)).^3+b(2).*(x-z(2)).^2+c(2).*(x-z(2))+d(2)), [-1 -.5], '-.r','linewidth',2);
Im sure this isnt the most efficient way but it got the job done haha.

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 29 de Jun. de 2020
ix = (g1 >= -1) & (g1 <= -.5); % follow the same for the rest
plot(x(ix), g1(ix))
  2 comentarios
the cyclist
the cyclist el 29 de Jun. de 2020
The fact that OP wrote
g(1)
rather than
g1
made me hesitate to suggest this solution. We'll see.
madhan ravi
madhan ravi el 29 de Jun. de 2020
Haha me too , I hate suspenses xD.

Iniciar sesión para comentar.

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by