There's a function to create handles and to set their tag?

2 visualizzazioni (ultimi 30 giorni)
Hi everybody!
I'm implementing a program for a university exam. This program has to read a file and make statistics about some voices...
I'm trying to create a program that could be universal, with this type of file... So, starting by uniques of my vectors, I need a function that's able to create (for example) push buttons and to set their tag as "PB_A", "PB_B", using progressive letters or numbers...
After that I should point to the handles to calculate and show the statistics...
There's something for me??
Thanks to everyone!

Risposta accettata

Walter Roberson
Walter Roberson il 12 Dic 2011
NButt = 5; %number of buttons
bh = zeros(NButt,1);
for K = 1 : NButt
bh(K) = uicontrol('Style', 'pushbutton', 'Tag', ['PB_', char('A' + K - 1)], 'Units', 'normalized', 'Position', [(K-1)/NButt 0 1/NButt 1]);
end
Now you just have to figure out how to do the callbacks automatically.
  4 Commenti
Walter Roberson
Walter Roberson il 12 Dic 2011
There were incorrect lower-case B's, now corrected.
That's what I get for changing variable names on the fly.
@Sean: At least I didn't use NumButt ;-)
Jethro
Jethro il 2 Gen 2012
I choose his answ because I used part of his code ;)

Accedi per commentare.

Più risposte (1)

Sean de Wolski
Sean de Wolski il 12 Dic 2011
Instead of having pba pbb pbc, use a cell array or even a vector to store their handles. That way you can do things with them all at once and you don't run into the FAQ4.6 issues.
For more reading, see what Matt did here: FEX:Matt_Fig's:GUIS
  3 Commenti
Sean de Wolski
Sean de Wolski il 12 Dic 2011
With pba, pbb, pbc, I'm trying to show your proposed labelling scheme for your pushbuttons and to recommend against it because of the issues in 4.6. Instead, build a vector of handles and reference it by index pb(1),pb(2) etc.
Walter Roberson
Walter Roberson il 12 Dic 2011
Jethro only asked for the Tag to be set to those values, and the Tag of an object an arbitrary string with no inherent meaning to MATLAB itself.
Graphic object tags of static items are used by GUIDE in the creation of routine names such as callbacks, and in the structure field name in the handles structure. It is possible that Jethro is referring to Tag in that sense, expecting routines to be automatically generated, but Jethro did not quite ask for that.
Recall for this matter that using dynamic structure field names is one of the alternatives listed in the FAQ.

Accedi per commentare.

Categorie

Scopri di più su Historical Contests 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!

Translated by