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!


