How to create listbox using uicontrol and not using Matlab GUIDE?
이전 댓글 표시
Hello,
I am trying the create listbox and text box using uicontrol and not using GUI! so anytime I click on one of the list items I get this error message 'Error: Function definitions are not permitted in this context'. I believe there is a problem with the definition of the Callback function. here is the code;
c = dialog('Position',[300 300 250 150],'Name','Select One');
txt = uicontrol('Parent',c,...
'Style','text',...
'Position',[75 120 100 15],...
'HorizontalAlignment','left',...
'String','Selected color is:');
listbox1 = uicontrol('Parent',c,...
'Style','listbox',...
'Position',[75 70 100 50],...
'Max',6,...
'String',{'Red';'Green';'Blue'},...
'Callback', @listbox1_Callback);
%
function listbox1_Callback(hObject, eventdata, handles)
file_list = get(handles.listbox1,'String');
index_selected = get(handles.listbox1,'Value');
filename = file_list{index_selected};
set(handles.txt,'String', filename);
end
Usually, when uicontrol function is called, the key-word 'Callback' refers to a function @NameOfTheFunction_Callback. this function must latter be defined so as the uicontrol could work as desired
function NameOfTheFunction_Callback (hObject, eventdata, handles)
Here you code the task this uicontrol performs anytime you activate it
end
what is wrong? Thank you
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!