Disabling Multiple uicontrol Buttons using array
Show older comments
I was wondering if there was anyway of disabling all the buttons in the array without a for loop? I can individually disable the buttons by referencing their positions within the array using the last statement in the code.
rez = get(groot,'ScreenSize');
buttonScaling = rez(3)/rez(4); %Dynamically scales size of buttons with resolution
H = .085*buttonScaling; %Height of button
W = .045; %Width of buttons
B2T = .727-3*H; %Distancing from Bottom 2 Top
L2R = .375; %Distancing from Left 2 Right
gap = .001; %Distance between buttons
number = 0; %Starting number
MAIN = figure('Position',rez,'Color','black','MenuBar','none','NumberTitle','off');
%Loop to automatically place down buttons and order them from 0 to 36
for across = 1:3 %//How many columns
B2T = .727-3*H; %//Resets height for each new column
for up = 1:3 %//How many rows
number = number + 1;
%//Checks if number is a member of the reds or blacks
if ismember(number, 1:7)
buttonColour = 'r';
elseif ismember(number, 7:9)
buttonColour = [0 0 0];
end
%An array called grid is created for debugging purposes, easy
%indexing for each button
grid{up,across} = uicontrol('style','pushbutton','units','normalized','position',[L2R, B2T, W, H],...
'String', number,'FontWeight','bold','FontSize',32,'Backgroundcolor',buttonColour,'ForegroundColor','w',...
'UserData', number, 'Callback', @bettingNumber);
B2T = B2T + (H + gap*buttonScaling); %//Shifts the next button down by the scaled gap
end
L2R = L2R+W+gap; %//Shifts the next column of numbers by the width of each button and the gap in between
end
grid{1,3}.Enable = 'Off';
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!