Callback errors when saving GUI under new name (using GUIDE)

1 visualizzazione (ultimi 30 giorni)
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
Stephen23
Stephen23 il 24 Giu 2016
Modificato: Stephen23 il 25 Giu 2016
@AM: to give us the files you can simply edit your question and upload the files using the paperclip button. No clutter!
AM
AM il 28 Giu 2016
Thanks for the info! I decided to forgo posting the code since it wasn't going to be helpful (looks like the issue was the saved .fig file.)

Accedi per commentare.

Risposta accettata

Sam Zorch
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
Sam Zorch
Sam Zorch il 24 Giu 2016
Oh, that is strange. Sorry, never seen anything like it.
AM
AM il 28 Giu 2016
So, I ended up starting a new GUI and copy/pasting all my callback code, which results in a GUI that functions as expected.
I have a feeling that my problem was related to this (specifically, the first answer) http://www.mathworks.com/matlabcentral/answers/241257-why-does-guide-delete-tags-to-axes-handles
I have a feeling I am guessing that at least one of the times, instead of saving my GUI using the GUIDE save (or save as) button, I used the save button from the actual GUI toolbar (which GUIDE gives you an option to add.) It appears that that may have saved the state of the figure and data as well, which I then loaded with GUIDE. One indication of this is that when I try to open the old file with GUIDE, I get the error that is described in that post.
Thanks for the help - I may have not gotten there otherwise. I'll make this as an answer since someone in the same scenario may find it helpful.

Accedi per commentare.

Più risposte (0)

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!

Translated by