MATLAB Answers

Listbox problem in GUI

6 views (last 30 days)
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 ...

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 24 Jun 2018
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}

  6 Comments

Show 3 older comments
Vasishta Bhargava
Vasishta Bhargava on 24 Jun 2018
I used num2str() but the column extracted from array still shows .. 'NaN'
Vasishta Bhargava
Vasishta Bhargava on 24 Jun 2018
it show 59 x 3 char array
Walter Roberson
Walter Roberson on 24 Jun 2018
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.

More Answers (0)


Translated by