Callback errors when saving GUI under new name (using GUIDE)
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I currently have a GUI that I built using GUIDE that has the desired behavior. I'd like to make major changes, but I want to do them under a different file name. So, in GUIDE, I do file->save as, and save a new file. GUIDE saves a new .fig and generates a new corresponding .m (the only changes from the previous one being that of changing the filename reference in the file.) I've done this before in the past with no issues.
*I'll put a note here that I've looked a quite a few forum Q/A's related to this, but none or the questions or solutions seemed to address my problem.
In this case, when I run the newly generated file (whether I run the .m or hit the green play button the the new .fig), I get an error right away (and I get further errors when I try to use the GUI controls - but I'll focus on the first error for now, since I'm hoping the cause is the same.) The function in which I get the error is as follows:
% --- Executes during object creation, after setting all properties.
function popup_freq_CreateFcn(hObject, eventdata, handles)
% hObject handle to popup_freq (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%Initialize related values
set(handles.popup_freq,'Value',4);
handles.viewFreq = 'ABC';
guidata(hObject, handles);
The error I get when I run the file is the following:
Struct contents reference from a non-struct array object.
Error in DataViewer2>popup_freq_CreateFcn (line 211)
set(handles.popup_freq,'Value',4);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in DataViewer2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)DataViewer2('popup_freq_CreateFcn',hObject,eventdata,guidata(hObject))
If I put a breakpoint in that line and observe the handles variable, I see that it is not a struct, it is simply an empty variable: []. So the error makes sense. However, I do not get this error when I run the original .fig .m pair. If I put a breakpoint at the same line in the same file, then handles is indeed a struct. Doing a text compare on the two .m files, the only difference that shows up is that references (and comments) to "DataViewer1" are changed to "DataViewer2", which is expected.
Any clues? I can put up the whole file if needed - I just didn't want to clutter the post.
Thanks
2 Commenti
Risposta accettata
Sam Zorch
il 24 Giu 2016
Sorry if this is a dumb suggestion, but have you searched for the string 'DataViewer1' in the DataViewer2 mfile? I seem to remember having a problem with GUIDE not recognizing everything it had to change. That wouldn't show up in the text compare. You might also bring up the property inspector for the control in GUIDE and see if there's anything funny in the 'CreateFcn' field.
Anyway, as the default commenting notes, 'handles' isn't defined until all the CreateFcns have run, so it should be empty at your breakpoint. I think the real puzzle is why DataViewer1 doesn't throw an error! So you might try to figure out when 'handles' is being defined in DV1, by putting similar breakpoints in each of the CreateFcns. As a general rule, it may be safer to put the initialization lines in the OpeningFcn, where 'handles' is sure to be defined.
If you don't figure out the problem, perhaps you could post the full code.
3 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!