필터 지우기
필터 지우기

How to reset the pop-up menu value in GUI?

조회 수: 3 (최근 30일)
Jomei
Jomei 2020년 3월 11일
댓글: Rik 2020년 3월 13일
Hi,
This is my pop-up coding.
function Domain_Callback(hObject, eventdata, handles)
contents = cellstr(get(hObject,'string'));
popchoice = contents{get(hObject,'value')};
if (strcmp(popchoice, 'Time Domain'))
Domain_value = 2;
elseif (strcmp(popchoice, 'Frequency Domain'))
Domain_value = 3;
elseif (strcmp(popchoice, '----'))
Domain_value = 1;
end
assignin('base', 'Domain_value', Domain_value);
And this is my reset button function
function Clear_button_Callback(hObject, eventdata, handles)
set(handles.Domain,'Value',1);
It partly works. In GUI if I press the reset button, the pop-up menu will show '----', but the value won't change.
So how can I reset the pop-up value to 1?
  댓글 수: 6
Geoff Hayes
Geoff Hayes 2020년 3월 11일
Jomei - but you do understand why the value is not being set in the workspace, correct? And do you really need it to be defined in the workspace? If so, why?
Jomei
Jomei 2020년 3월 13일
Thanks for replying.
As you said, I don't need to define the value when I want to reset the programme. Thus I just using evalin().

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

답변 (2개)

Rik
Rik 2020년 3월 11일
If you need something in your base workspace to be updated when you change things in your GUI, you could consider a programmatic class-based GUI. The example in the how to create a GUI thread should be relatively easy to adapt to your needs.
This different design would also remove the need for assignin.
  댓글 수: 1
Jomei
Jomei 2020년 3월 13일
It's really useful link. Thanks

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


Jomei
Jomei 2020년 3월 13일
편집: Jomei 2020년 3월 13일
Hi,
I think I know how to solve it, just simply clear the workspase valye by using evalin().
  댓글 수: 1
Rik
Rik 2020년 3월 13일
You should really avoid that strategy. It is very prone to breaking in ways that are difficult to diagnose. You should really consider changing your setup to one of the ways described in the link I posted.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by