Multiple Edit boxes and PPmenus

4 visualizaciones (últimos 30 días)
Santosh
Santosh el 25 de Abr. de 2013
I am using GUIDE to build a MATLAB GUI.
I have 24 edit text boxes on the GUI.
How can I use loop in the code (like: for i = 1 to 24) to retrieve and store the contents of these components in to a 24 by 1 array.
Have I had less edit text boxes, I could manually name each box as textbox1, textbox2 and retrieve the contents of it using get(handles.textbox1,'String') but I have so many text boxes. I want to avoid manually naming them as textbox1 .....to textbox24 and then retrieve data from each of the text boxes.
Is there any easy way to do this.
Appreciate the help
Thanks, Santosh

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Abr. de 2013
boxvals = cell(24,1);
for i = 1 : length(boxvals)
boxvals{i} = get( handles.(sprintf('textbox%d', K)), 'String' );
end
If you were not using GUIDE, or are willing to add in non-GUIDE code to create the boxes, then like I showed in response to your last question, create them in a loop and store the handles.
nbox = 24;
editboxes = zeros(nbox,1);
for K = 1 : nbox
editboxes(K) = uicontrol( 'Style', 'edit', 'Units', 'norm', 'Position', [1/2 (nbox-K)/nbox 1/2 1/(nbox+1)], 'String', {sprintf('edit box #%d', K)} );
end
then to fetch,
boxvals = cell(nbox, 1);
for K = 1 : nbox
boxvals{i} = get( editboxes(K), 'String' );
end
  1 comentario
Santosh
Santosh el 26 de Abr. de 2013
Walter,
Thanks for the advice, this works great.
I think, I have spent too much time on how to program with GUIDE, so I am just going to stick with it instead of doing the programmatic gui development. However, I am paying attention to the code that you posted for programmatic gui development and it makes a lot of sense to me
Really Aprreciate this, Santosh

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Event Functions en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by