Controlling Programatically Created Array of Buttons in Another Callback

5 views (last 30 days)
To begin, I setup my code similar to this example Here
My goal is to create an array of NxM rowsxcols of state buttons. If the row/col of the button exists in a separate list, then the button is given a value of "1" and made green and enabled, where those that just fill in the rest of the array are given a value of "0", made red and disabled. Each button is assigned to a callback that utilizes the src.Text or src.Value to determine what button was pressed. If a button is pressed it changes color from red to green. This all works well.
The problem that I can't seem to overcome is how do I reference individual buttons in other callbacks or throughout the script? A good example would be how to program a "Select All" or "Deselect All" button. Even though each button is assigned to a UniButton(i,j) this lies within the callback function that loads the list and the array and therefore is not accessible outside of that function. Assigning the 'app.' properties yields a 'Unable to perform assignment because dot indexing is not supported for variables of this type.' error. Maybe I am missing something fundamental as I am not a programmer.
Another example of something that would be nice is to be able to pull the current state of all the buttons in the array.
The code is below
function mybuttonpress(app,src,event)
src.Value
src.Text
if src.BackgroundColor==[0 1 0]
src.BackgroundColor=[1 0 0];
else
src.BackgroundColor=[0 1 0];
end
end
function LoadFileButtonPushed(app, event)
CellContOne=containers.Map(totalrows,totalrows2);
allKeys = string(keys(CellContOne));
for i=1:rows
for j=1:cols
UniButton(i,j) = uibutton(app.Panel, 'state'); %Creating a Button
UniButton(i,j).Position = A; %Giving the Button a position
UniButton(i,j).Text = totalrows(j,i);
UniButton(i,j).BackgroundColor=[1 0 0];
if ismember(allKeys(w),app.srscs)
UniButton(i,j).BackgroundColor=[0 1 0];
UniButton(i,j).Value=1;
else
UniButton(i,j).Enable=0;
end
UniButton(i,j).ValueChangedFcn = @app.mybuttonpress; %Callback function
A(1) = A(1) + sizeW; %Position change for the next Button
w=w+1;
end
A(1)=1;
A(2) = A(2) - sizeL;
end
end
function DeselectAllButtonPushed(app, event)
?????
end

Answers (0)

Categories

Find more on Environment and Settings 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!