MATLAB Answers


Listbox problem in GUI

Asked by Vasishta Bhargava on 24 Jun 2018
Latest activity Commented on by Walter Roberson
on 24 Jun 2018
I have a GUI which has listbox in which I want to display numbers in first followed by strings or names The excel file has numbers and texts/names. How can I display both numbers and text in listbox using pushbutton callback Matlab is treating text as 'NaN' and I want to convert them to strings and display as text in listbox ...


Sign in to comment.

1 Answer

Walter Roberson
回答者: Walter Roberson
2018 年 6 月 24 日

You need to initialize the listbox as a cell array and use {} indexing with it. For example,
s = {3; 'hello'};
h = uicontrol('style','list','string', s);
hv = get(h,'Value');
hall = get(h,'String');
hcurrent = hall{hv}


Vasishta Bhargava 2018 年 6 月 24 日
I used num2str() but the column extracted from array still shows .. 'NaN'
Vasishta Bhargava 2018 年 6 月 24 日
it show 59 x 3 char array
Walter Roberson
2018 年 6 月 24 日
It is not possible for a numeric array to contain both text and numbers.
If you are using xlsread() then the first output would be pure numeric with no text, and the second output would be pure text with no numeric, and the third output ("raw") would be a cell array in which individual entry could be either numeric or character vector. As that is the only way to get a mix of numeric and text with xlsread(), I assumed that you were working with that third output of xlsread()
I just corrected a typing mistake in the code I posted.

Sign in to comment.