Fix one curve, while change another

4 visualizaciones (últimos 30 días)
TARAM
TARAM el 21 de Oct. de 2019
Editada: TARAM el 22 de Oct. de 2019
Hi dear matlab users. Is it possible to fix one curve on axis and update another one using, for exhample, slider.
Of course i can plot two curves every time i move slider's button:
1) sample curve, that does not change;
2) changeable curve;
But i dont think that this solution is rational.
  1 comentario
darova
darova el 21 de Oct. de 2019
Can you be more specific? Show some examples? ImageS?

Iniciar sesión para comentar.

Respuesta aceptada

Jon
Jon el 21 de Oct. de 2019
Editada: Jon el 21 de Oct. de 2019
Here is one approach. You can modify the YData property of the second curve. Here is a little example
x = 1:10
y1 = x;
y2 = x.^2
p = plot(x,y1,x,y2)
% change second curve to plot the sin(x) instead
% just for demo, pause long enough to see original curve before
% changing to the new one
pause(3)
p(2).YData = sin(x)
If you are doing this within a MATLAB GUI built using app designer you could do something like this with your callbacks. In this toy example, the button push make the plot with the original two curves and then the slider modifies the second curve
% Button pushed function: Button
function ButtonPushed(app, event)
% make initial plot
x = 1:10;
y1 = x;
y2 = x.^2;
plot(app.UIAxes,x,y1,x,y2)
end
% Value changing function: Slider
function SliderValueChanging(app, event)
changingValue = event.Value;
% get the current YData for the original curve
x = app.UIAxes.Children(1).XData; % first child is last curve plotted
% change the original curve according to slider value
app.UIAxes.Children(1).YData = changingValue/100*x.^2;% just an example of changing curve
end
end

Más respuestas (0)

Categorías

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

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by