Can I do this with LOOPING

조회 수: 1 (최근 30일)
Salim Muhammad
Salim Muhammad 2017년 1월 30일
댓글: Salim Muhammad 2017년 2월 1일
Hello, i want to make some sorting program. from 2 pushbutton (pushbutton A and B) callback and with some value and the sorting in listbox. so when i push the pushbutton A, it will show the button name and the value in listbox. something like this (A, 12) with A is the name and 12 is the value. and later when i push button B with value 3 (B, 3) it should have be in the first listbox apart (A, 12) because the value in B is smaller and so everytime we press the button it will show the name and the value and if the value is smaller it will be in the first and if larger it will be in the next one. i can't use some larger and smaller operator because in the listbox they become string. how can i compare the value in the list box?

채택된 답변

Walter Roberson
Walter Roberson 2017년 1월 31일
Consider storing the numeric values in the UserData field of one of the controls.
ud = get(handles.listbox1, 'UserData');
if isempty(ud)
ud = struct('as_string', {{}}, 'as_numeric', []);
end
new_str = [ud.as_string, new_string];
new_num = [ud.as_numeric, new_number];
[new_num, sort_order] = sort(new_num);
new_str = new_str(sort_order);
ud.as_string = new_str;
ud.as_numeric = new_num;
set(handles.listbox1, 'UserData', ud);
and now you can set the listbox string to new_str
  댓글 수: 1
Salim Muhammad
Salim Muhammad 2017년 2월 1일
Awesome, it's work

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by