关于GUI编程的一个问题!
<P>各位好!我想请教大家一个问题:我用matlab的GUI设计工具设计了一个界面,界面是一个listbox控件,控件里面有8项,每次用户选中某一项时会弹出相应的新窗口,以下是我编写的listbox控件的callback例程代码:<BR><BR>function listbox1_Callback(hObject, eventdata, handles)<BR>% hObject handle to listbox1 (see GCBO)<BR>% eventdatareserved - to be defined in a future version of MATLAB<BR>% handles structure with handles and user data (see GUIDATA)</P><P>% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array<BR>% contents{get(hObject,'Value')} returns selected item from listbox1<BR>index=get(handles.listbox1,'value');<BR>switch index<BR> case 1<BR> openfig('xxbxlsbcs','reuse');<BR> case 2<BR> openfig('fcbxlsbcs','reuse');<BR> case 3<BR> openfig('gcbxlsbcs','reuse');<BR> case 4<BR> openfig('sbtbxlsbcs','reuse');<BR> case '5<BR> openfig('sblbxlsbcs','reuse');<BR> case 6<BR> openfig('gpbxlsbcs','reuse');<BR> case 7<BR> openfig('mlbxlsbcs','reuse');<BR> case 8<BR> openfig('jsbxlsbcs','reuse');<BR>end<BR> 但是我每次在控件中选中某一项时,matlab窗口就显示以下错误代码:<BR><BR>??? Attempt to reference field of non-structure array.</P>
<P>Error in ==> sbcssr>listbox1_Callback at 86<BR>index=get(handles.listbox1,'value');</P>
<P>Error in ==> gui_mainfcn at 75<BR> feval(varargin{:});</P>
<P>Error in ==> sbcssr at 44<BR> gui_mainfcn(gui_State, varargin{:});</P>
<P>??? Error while evaluating uicontrol Callback.<BR><BR>请高手们帮指导一下我的编程出了什么问题,不胜感激!</P>
回复:(xipizb)关于GUI编程的一个问题!
错误和给的代码好像没什么关系阿 错误很可能是由于前面用GUIhandles和guidata搜集handle变成结构数组时,没有对相应的句柄标明tag,导致域名handles.listbox1不存在而致.单步调一下即可,应该不难
页:
[1]