MATLAB Answers

0

Error in function of GUI(list_box)

Asked by shengchang gao on 21 Jun 2019
Latest activity Answered by Geoff Hayes
on 30 Jun 2019
Hi, I try to use the GUI to change the Simulink block name. When I add the list_box in my GUI design, I want to return the selected item. The MATLAB comments said that use contents{get(hObject,'Value')} returns selected item from listbox1 . However,when I try to use the contents function and to assign the value to another variable, MATLAB show me the error. The contents function is undefined.
01.PNG02.PNG
Thank you!

  0 Comments

Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 30 Jun 2019

shengchan - I think what was missing from your code was the initialization of the contents variable...and so when you try to use it with
blocks = contents(get(hObject, 'Value'));
you probably get the Undefined function or variable 'contents'. Try doing
contents = cellstr(get(hObject, 'String'));
blocks = contents(get(hObject, 'Value'));
so that contents is defined before you use it.

  0 Comments

Sign in to comment.