Disabling Multiple uicontrol Buttons using array

14 vues (au cours des 30 derniers jours)
David
David le 5 Déc 2022
Modifié(e) : Voss le 5 Déc 2022
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';

Réponse acceptée

Voss
Voss le 5 Déc 2022
Modifié(e) : Voss le 5 Déc 2022
Yes. For instance to disable all uicontrols in column 3 of grid:
set([grid{:,3}],'Enable','off')
By the way, you can store uicontrols in an array (cell array not required):
grid = zeros(3); % numeric array
for i = 1:3
for j = 1:3
grid(i,j) = uicontrol(...)
end
end
which would make the syntax a little simpler:
set(grid(:,3),'Enable','off')

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by