필터 지우기
필터 지우기

uicontrol popup 0 selection problem

조회 수: 1 (최근 30일)
GLW
GLW 2013년 7월 18일
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'));

채택된 답변

David Sanchez
David Sanchez 2013년 7월 18일
You are not popping up the selected value but the position of the selected value. Since you start at 0, it looks it pops up the selection plus 1.
  댓글 수: 1
GLW
GLW 2013년 7월 18일
that makes sense, thanks for that.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by