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

조회 수: 2 (최근 30일)
Jethro
Jethro 2011년 12월 12일
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!

채택된 답변

Walter Roberson
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
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 ;-)
Jethro
Jethro 2012년 1월 2일
I choose his answ because I used part of his code ;)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
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.
For more reading, see what Matt did here: FEX:Matt_Fig's:GUIS
  댓글 수: 3
Sean de Wolski
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
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 CenterFile Exchange에서 Probability Distributions에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by