How to load values according to popup menu choice?

2 views (last 30 days)

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 Comments
Rik
Rik on 1 Oct 2018
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 on 5 Oct 2018
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?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 5 Oct 2018
Edited: Walter Roberson on 5 Oct 2018
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

Categories

Find more on Variables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!