Multiple Edit boxes and PPmenus
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Walter Roberson
il 25 Apr 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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Event Functions in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!