There's a function to create handles and to set their tag?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2011-12-12
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 个评论
Walter Roberson
2011-12-12
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 ;-)
更多回答(1 个)
Sean de Wolski
2011-12-12
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.
3 个评论
Sean de Wolski
2011-12-12
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
2011-12-12
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Probability Distributions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!