Multiple Edit boxes and PPmenus

4 vues (au cours des 30 derniers jours)
Santosh
Santosh le 25 Avr 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

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Avr 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 commentaire
Santosh
Santosh le 26 Avr 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Event Functions 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