How to plot 2 graphs using the 2 axes and 2 push buttons? I have created 2 axes and 2 push buttons namely as below:
axes1
axes2
pushbutton1
pushbutton2
In the pushbutton1 property I have inserted the "Callback" column with
>>plot(simout.time,simout.signals.values)
from my simulink.
In the pushbutton2, I did the same thing to the "Callback" as
>>plot(simout1.time,simout.signals.values)
from my simulink.
The "keypressFcn" in pushbutton1 and pushbutton2 are referred to axes1 and axes2 respectively. However, the result only shown in axes1 when I press those 2 buttons. What is the problem?

 채택된 답변

Paulo Silva
Paulo Silva 2011년 3월 23일

0 개 추천

You can select what's the current axes like this
axes(h) %h is the handle for the axes, for example h=handles.axes1
%your code goes here, any graphic function will appear on axes1

댓글 수: 3

Kai Hao Then
Kai Hao Then 2011년 3월 23일
Where should I put the code?
I just want to create a GUI with 1 pushbutton to plot in a figure and another pushbutton to plot in another figure.
In the pushbutton1 properties, I used
>>plot(simout.time,simout.signals.values)
in the Callback and
>>axes1
in the KeyPressFcn.
In the pushbutton2 properties, I used
>>plot(simout1.time,simout1.signals.values)
in the Callback and
>>axes2
in the KeyPressFcn.
This turns out to be 2 pushbuttons plot in the same figure (axes1) only. While axes2 has nothing.
Paulo Silva
Paulo Silva 2011년 3월 23일
axes(axes1);plot(simout.time,simout.signals.values)
Paulo Silva
Paulo Silva 2011년 3월 23일
put the code inside '''''

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jarrod Rivituso
Jarrod Rivituso 2011년 3월 23일

0 개 추천

Try directing the plot to the axes handle.
For instance...
>> ah1 = subplot(2,1,1);
>> ah2 = subplot(2,1,2);
>> plot(ah1,1:10)

댓글 수: 4

Kai Hao Then
Kai Hao Then 2011년 3월 23일
Hi Jarrod,
Thanks for the answer.
But the problem is I have 2 push buttons and 2 axes and I tagged each push button to each axes but in the end it turned out to be only 1 graph.
I clicked pushbutton1 the result is shown in axes1 and when I clicked pushbutton2 the result is still shown in axes1. When I click pushbutton2, it should be in axes2.
Do you know where is the problem?
Jarrod Rivituso
Jarrod Rivituso 2011년 3월 23일
It sounds like you are using GUIDE. GUIDE callbacks all have a third input argument that is a structure of handles.
So, if you are using GUIDE, you should be able to write something like...
>> plot(handles.axes1,x,y)
Kai Hao Then
Kai Hao Then 2011년 3월 24일
However, I still get an error running this GUIDE.
??? Undefined variable "handles" or class "handles.axes1".
??? Error using ==> struct2handle
Error while evaluating uicontrol CreateFcn
Please advise.
sama
sama 2015년 10월 13일
@Jarrod Rivituso Your answer helped me thanks a lot. I have a quick question please. When I use subplot and push bottom, the plots are stretched and cover all other bottoms.Would you please give me advice!Thanks

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2011년 3월 23일

댓글:

2015년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by