uicontrol popup 0 selection problem
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
David Sanchez
le 18 Juil 2013
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!