필터 지우기
필터 지우기

Want to draw two axes using a single popupmenu

조회 수: 2 (최근 30일)
ahasan ratul
ahasan ratul 2018년 4월 7일
답변: Munish Verma 2021년 12월 12일
I haven't used matlab gui before. I want to draw two plots using a popup menu. Suppose, I want to plot cm and mm values in two axes Using a popup menu which has multiple object names. So each time I select one option from popup menu it shows both cm and mm values in two different axes. Any help with an example is highly appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2018년 4월 7일
function popup1_Callback(hObject, event, handles)
all_strings = get(hObject, 'String');
if ischar(all_strings); all_strings = cellstr(all_strings); end
which_chosen = get(hObject, 'value');
chosen_string = all_strings{which_chosen};
ax1 = handles.axes1;
ax2 = handles.axes2;
switch chosen_string
case 'lollipop':
plot(ax1, 1:20, rand(1,20));
plot(ax2, 1:20, rand(1,20)*10);
case 'ping-pong':
plot(ax1, 1:20, randn(1:20));
plot(ax2, 1:2), randn(1:20)*10);
end
  댓글 수: 2
ahasan ratul
ahasan ratul 2018년 4월 7일
편집: Walter Roberson 2018년 4월 7일
I have tried your code but it shows plots for only 1st popup menu. when i select 2nd one, It shows an error and the previous two graphs are not updated to new graphs.
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)untitled('popupmenu1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
and
following is the code that i used:
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
all_strings = get(hObject, 'String');
if ischar(all_strings); all_strings = cellstr(all_strings); end
which_chosen = get(hObject, 'value');
chosen_string = all_strings{which_chosen};
ax1 = handles.axes1;
ax2 = handles.axes2;
switch chosen_string
case 'head'
plot(ax1, 1:20, rand(1,20));
plot(ax2, 1:20, rand(1,20)*10);
case 'head_end'
plot(ax1, 1:50, randn(1:50));
plot(ax2, 1:50, randn(1:50)*10);
end
Walter Roberson
Walter Roberson 2018년 4월 7일
plot(ax1, 1:50, randn(1:50));
plot(ax2, 1:50, randn(1:50)*10);
should be
plot(ax1, 1:50, randn(1,50));
plot(ax2, 1:50, randn(1,50)*10);

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

추가 답변 (1개)

Munish Verma
Munish Verma 2021년 12월 12일
plot(ax1, 1:50, randn(1,50));
plot(ax2, 1:50, randn(1,50)*10);

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by