[GUI] How do you get only one element in a listbox

조회 수: 2 (최근 30일)
Shane
Shane 2012년 12월 17일
I know you are able to obtain all the elements in a string from the listbox with:
get(handles.listbox1, 'String')
But what if I only want the second or fourth element in the listbox?
Thanks in advance <3

채택된 답변

Image Analyst
Image Analyst 2012년 12월 17일
You have to read in the whole thing anyway. Then get the value property and use that to index into the string.
listboxItems = get(handles.listbox1, 'string');
selectedItems = get(handles.listbox1, 'value');
selectedItem = listboxItems(selectedItems);
  댓글 수: 4
Walter Roberson
Walter Roberson 2012년 12월 17일
Change
listboxItems = get(handles.listbox1, 'string');
to
listboxItems = cellstr( get(handles.listbox1, 'string') );
Shane
Shane 2012년 12월 17일
Thank you soo much Walter I appreciate it!!!

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

추가 답변 (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