How can I plot more than 1 signal in the same axes within the GUI figure?

I have created a GUI which includes options to select the signals to be represented and a single axes window. I would like to represent all the selected signals in the axes at the same time. How can I do that? Any advice would be helpful. Thank you!

 Risposta accettata

Hello Eva,
Use "hold on" in your code to plot multiple signals on same axis.
For example, see this:
clear;
clc;
t = -pi : 0.1 : pi;
x = sin(t);
y = cos(t);
plot(t,x,'color','r');
hold on;
plot(t,y,'color','b');

6 Commenti

Thank you, I've already tried that but it doesn't work. Any suggestion about what could be the problem?
@Eva Gil: well, we don't know what you tried, nor what "but it doesn't work" actually means: did it plot incorrect data, did you get a warning, did MATLAB stop responding, did you get an error message, or perhaps your PC caught fire? Should I call the fire brigade?
Or, if " but it doesn't work" is something less life-threatening, perhaps you could tell us exactly what you tried, what you expected, and what happened (including the complete error message text, should you get any).
Sorry Stephen. You're right. The command 'hold on' works. The problem was that I didn't specify the axes where it had to be represented. An example about how the code should be written:
x=1:100;
y=2*x;
y2=x.^2;
axes(handles.axes1);
plot(x,y);
hold on;
plot(x,y2);
Next time I'll explain myself far better. Thank you for your time and advices (I'm a newbie)
You said you had "a single axes window" so you have only one axes. The plots should have been there and the call to axes() should not have been needed.
Eva
Eva il 25 Mag 2017
Modificato: Eva il 26 Mag 2017
It was what I thought, but it didn't work until I called axes().
Hahaha Stephen, that was rude buddy. Anyways you said the truth.
Hello Eva, don't feel sorry if you are a newbie. We are here to correct you and support you.
Keep exploring!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Tag

Richiesto:

Eva
il 25 Mag 2017

Modificato:

Eva
il 26 Mag 2017

Community Treasure Hunt

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

Start Hunting!

Translated by