What is the difference between opening a GUI from Guide and just double clicking it in my workspace
Show older comments
I have been working on building a GUI that will accept data and translate it into a text file. Anytime I tried to use the get(handles.object_name, 'String') I would get an error saying "Attempt to reference field of non-structure array" I then decided to try the tutorial "two_axes" IF I open this figure up by double clicking the file in my workspace and I hit plot then I get the same error. However if I open the figure in GUIDE and then hit the play button it works just fine. My question is why will it work one way but not the other. I feel like I have a weird setting or something but have not been aable to find an answer. I am working in the Matlab R2014b environment.
Thanks
Answers (2)
Image Analyst
on 7 Jan 2015
0 votes
Search your code for "clear" - chances are, one of your callbacks calls clear which blows away your handles structure by calling clear, clearvars, delete, or one of its friends/variants.
2 Comments
Image Analyst
on 7 Jan 2015
Kevin's "Answer" moved here since it's a reply to me and not an answer to his original question:
Thanks for your response. There is no "clear" command in my code. The code works just fine if I launch it from the editor. But if I call it from the workspace then I get the error and it always references the get(handles.object, 'String')
Image Analyst
on 7 Jan 2015
Edited: Image Analyst
on 7 Jan 2015
What does "launch it from the editor" mean? Exactly how did you run it? Click the green triangle Run button on the MATLAB toolbar? Click the green triangle Run button on the GUIDE toolbar? Type the F5 key?
What does "call it from the workspace" mean? Type the m-file name in the command window? Double-click a fig file in the Current Folder panel? Something else?
Geoff Hayes
on 9 Jan 2015
Kevin - when you double-click on the GUI fig file, it opens and displays all of the controls and that is it. Opening the GUI in this way skips certain variable initializations that would normally occur when you launch the GUI correctly. A GUI can only be launched through GUIDE, by pressing the run button while viewing/editing the GUI m file in the editor, or by calling your GUI by name from the command line as
>> myGui
2 Comments
Harris Yong
on 15 Sep 2016
Interesting. Is there a way to prevent people from opening the GUI by double-clicking on the .fig file? Several users in my group are complaining that the GUI doesn't work properly, but it's because they're opening it by double-clicking.
Image Analyst
on 15 Sep 2016
Before the line where it says
% Begin initialization code - DO NOT EDIT
put this code:
if nargin ~= 0
close gcf;
return;
end
% Begin initialization code - DO NOT EDIT
You can also craft an error message and display it if you want, before the return:
errorMessage = sprintf('You cannot.......
uiwait(errordlg(errorMessage));
return;
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!