How to load values according to popup menu choice?

조회 수: 2 (최근 30일)
Bari khan
Bari khan 2018년 10월 1일
편집: Walter Roberson 2018년 10월 5일

I have a popup menu.

And the popup menu has three choices.

I wish to load amount of money such as $5,$6,$8 for clicking the choices in popup menu,set it in the GUI's uitable and store it for calculations. How can I do that? Please help.

  댓글 수: 2
Rik
Rik 2018년 10월 1일
Use a set of conditional statements (either if, elseif and else, or switch and case) in the callback to the popup menu.
Bari khan
Bari khan 2018년 10월 5일
If I choose from the popup menu, the previous data is cleared. What code do I need to use to ensure that the previous data does not get cleared?

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 10월 5일
편집: Walter Roberson 2018년 10월 5일
Your code has function popupmenu1_Callback that contains
contents = cellstr(get(hObject,'String'))
pop=contents{get(hObject,'Value')}
for i=1:4
sel_sts{i,1}='i';
end
if(strcmp(pop,'Pop-up Menu'))
set(handles.uitable1,'data',sel_sts);
elseif(strcmp(pop,'book'))
set(handles.uitable1,'data',sel_sts);
elseif(strcmp(pop,'pen'))
set(handles.uitable1,'data',sel_sts);
end
Each of those set() is replacing the existing data in the uitable with the new cell array sel_sts .
Note that you are doing the same set() each time, so your code could be compressed to
if ismember(pop, {'Pop-up Menu', 'book', 'pen'})
set(handles.uitable1, 'data', sel_sts);
end
I wonder, by the way, if you really want to set those entries to the literal character 'i' in the for loop, or if you want the value of i?
for i = 1 : 4
sel_sts{i,1} = i;
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by