Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Error in function of GUI(list_box)
조회 수: 1 (최근 30일)
이전 댓글 표시
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.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/225773/01.png)
![02.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/225774/02.png)
Thank you!
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!