Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error in function of GUI(list_box)

1 回表示 (過去 30 日間)
shengchang gao
shengchang gao 2019 年 6 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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!

回答 (1 件)

Geoff Hayes
Geoff Hayes 2019 年 6 月 30 日
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.

Community Treasure Hunt

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

Start Hunting!

Translated by