setting handles for an array of pushbuttons (i.e. pushbutton(i))

7 visualizaciones (últimos 30 días)
i want to set handles for an array of pushbuttons starting from pushbutton1 to pushbutton10 (i.e. pushbutton(i)), is this possible in Matlab? for example a code look like
for i=1:10
set(handles.pushbuttton(i),'String','i')
end
thanks..
  3 comentarios
kaan yilmaz
kaan yilmaz el 12 de Mzo. de 2012
This code doesn't work... briefly, i have 300 buttons in my GUI and i made this Gui by GUIDE, i need to save the states of these buttons(i.e.backgroundcolors), but i cannot do it each time like "state.pushbutton1=get(handles.pushbutton1,'Backgroundcolor'); " for 300 buttons, therefore i need to make an array for which i need to write "state.allpushbuttons=get(handles.allpushbuttons,'Backgroundcolor'); "
could i explain it clear enough?
Jan
Jan el 12 de Mzo. de 2012
Your code sets the string of the buttons to 'i'. Your comment means, that you want to get the BackgroundColor. Both are different problems.

Iniciar sesión para comentar.

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 12 de Mzo. de 2012
It doesn't work because handles.pushbutton(i) does not evaluate to handles.pushbutton1 (when i is one). To work around this with GUDIE you would either need to use dynamic field names (recommended) or eval
e.g.:
set(handles.(sprintf('pushbutton%d',1)),'String',num2str(i))
or
set(eval(eval('sprintf(''handles.pushbutton%d'',1)')),'String','i')
which is highly recommended against.
  1 comentario
kaan yilmaz
kaan yilmaz el 12 de Mzo. de 2012
woow, thank you, the thing i wanted to do is exactly similar to this, it would be great if these codes work, thk you so much..

Iniciar sesión para comentar.

Más respuestas (2)

kaan yilmaz
kaan yilmaz el 12 de Mzo. de 2012
why does nobody answer this question? please help, i got stuck here :(

Jan
Jan el 12 de Mzo. de 2012
This will get the background color of all buttons as a cell:
state.allpushbuttonBG = get([handles.pushbutton],'Backgroundcolor');
and to set it later:
set([handles.pushbutton], 'Backgroundcolor', state.allpushbuttonBG);
I cannot try it currently, perhaps you need addition curly braces:
set([handles.pushbutton], {'Backgroundcolor'}, state.allpushbuttonBG);
  2 comentarios
kaan yilmaz
kaan yilmaz el 12 de Mzo. de 2012
thnk you too, Mr. Simon, i will try this also, new ideas :)
kaan yilmaz
kaan yilmaz el 12 de Mzo. de 2012
[handles.pushbutton] --> sadly, Matlab cannot understand handle of all pushbuttons in the figure by this command...

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by