How can i make an alternating tag when setting a variable in for a "static text" in a GUI?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi. Her comes a long question, but I really am unable to figure out the answer. The question is thorough, so I can get the correct answer. Thank you.
At the moment I am working on creating a rating system for billiards for me and my classmates. One of the UIs of the program is going to show the top 20 rated players in the database. For this, I have made a UI in the guide from MATLAB. This GUI shows the username and the rating of the current top 20 players. The interface is added below:
When doing this, I want to use a for-loop. This is because the database in the beginning will contain less than 20 players. If not, all the 20 players could have been hardcoded into the UI with username and rating(with 40 lines of code). Nonetheless, this would not work with less than 20 players. The code which concerns the editing of the "static text" boxes, placing the username and the rating in the right taged box, in the GUI-matlab code is given below:
function varargout = top_20_rating_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
top_20 = evalin('base','top');
top_20_cell = evalin('base','top_20_cell');
for i = 1:top_20
set(handles.(eval(sprintf('username_%d',i))),'string',top_20_cell{i,1});
set(handles.(eval(sprintf('rating_%d',i))),'string',top_20_cell{i,2});
end
top_20_cell is a cell array containing the, up to, 20 best players. top_20 is the number of players in the list, if less than 20. The i in the for-loop is used for both getting the information from the cell array and making the tag. The tags are rating_1, rating_2 ... rating_20, and username_1, username_2 ... username_20. I have tried to create the tag with the integer from the for-loop but it doesn't work.
I hope that someone can help me out :)
0 件のコメント
回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!