How to load values according to popup menu choice?
2 次查看(过去 30 天)
显示 更早的评论
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
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.
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!