uicontrol popup 0 selection problem
이전 댓글 표시
The following piece of code is an extract of a function that I am currently developing.
The extract has 3 popup uicontrol selections A,B,C. A & C require that the user can select '0' or other values, B doesn't require selection of '0' from the popup.
When you click the generate button, the extracted values are output to the command window. With the default values selected (0,1,0) Why is it that A&C never output the selected value, they output selected value + 1, where B outputs the selected value?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [] = test()
S.fh = figure('NumberTitle','off','Visible','on', 'Menu','none', 'Name','tst');
movegui(S.fh,'center')
S.mrSign = uicontrol('Style', 'popup',...
'String', '0|1',...
'Position', [20 340 100 50]);
uicontrol('Style','text','Position', [20 400 100 15], 'String' ,'A')
S.mrWl = uicontrol('Style', 'popup',...
'String', '1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32',...
'Position', [130 340 100 50]);
uicontrol('Style','text','Position', [130 400 100 15], 'String' ,'B')
S.mrFl = uicontrol('Style', 'popup',...
'String', '0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32',...
'Position', [240 340 100 50]);
uicontrol('Style','text','Position', [240 400 100 15], 'String' ,'C')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% S.pb = uicontrol('Style', 'pushbutton', ... 'String', 'Generate', ... 'BackgroundColor', 'red', ... 'Position', [200 30 140 50]);
set(S.pb,'callback',{@pb_call,S}); % Set the callback, pass parameters as structure.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Generate button callback %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [] = pb_call(varargin) % Callback for pushbutton. S = varargin{3}; % Get structure. fprintf('mr_sign = %d\n',get(S.mrSign,'val')); fprintf('mr_wl = %d\n',get(S.mrWl,'val')); fprintf('mr_fl = %d\n',get(S.mrFl,'val'));
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!