MATLAB Answers

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

4 views (last 30 days)
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!

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Dec 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 Comments

Show 1 older comment
Walter Roberson
Walter Roberson on 12 Dec 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 on 2 Jan 2012
I choose his answ because I used part of his code ;)

Sign in to comment.

More Answers (1)

Sean de Wolski
Sean de Wolski on 12 Dec 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 Comments

Jethro
Jethro on 12 Dec 2011
I'm sorry, I didn't understand the first part of ur answ :P
"Instead of have ing pba pbb pbc"
Sean de Wolski
Sean de Wolski on 12 Dec 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 on 12 Dec 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.

Sign in to comment.