GUI- "Attempt to reference field of non-structure array." Error with varargout and using red x to close
1 次查看(过去 30 天)
显示 更早的评论
A similar question was already asked but the link to the solution ( http://www.mathworks.com/support/solutions/data/1-193LD.html?solution=1-193LD ) has expired I think because I can't view it so I figured I would ask it again since similar questions don't seem to relate to varargout:
Error using waitfor Error while evaluating uicontrol Callback
Attempt to reference field of non-structure array.
Error in SaveMethod>SaveMethod_OutputFcn (line 207) varargout{1} = handles.output;
Error in gui_mainfcn (line 263) [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
Error in SaveMethod (line 40) [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
I get the error when I try to close my GUI window with the red x in the corner (as opposed to a back button I usually use to close). I also tried to include a uiwait in my opening and then uiresume in my output functions but I still got the same error.
Any solutions?
P.S. This is my outputfcn: varargout{1} = handles.output; set(handles.figure1,'Visible','off')
2 个评论
Geoff Hayes
2014-7-10
Megna - the error attempt to reference field of non-structure array in this case means that the handles structure is not considered a structure (it has no fields) and is probably empty. If you were to put a breakpoint at this line and run the GUI, you could see if that were the case.
Have you made any changes to the yourGuiName_OpeningFcn or to the code that initializes the GUI?
How do you run the GUI - from the Command Window or from within GUIDE?
Why, in the yourGuiName_OutputFcn, do you invoke the line
set(handles.figure1,'Visible','off')
It may help to attach your m file and fig file to your question so that someone else can run it and see if they can reproduce your behaviour.
采纳的回答
Geoff Hayes
2014-7-10
I launched the GUI (through GUIDE) and observed the same results as you - when I pressed the close button (x), the error message Attempt to reference field of non-structure array appeared from the SaveProcessingMethod_OutputFcn function.
This is occurring because of the last statement in the SaveProcessingMethod_OpeningFcn
waitfor(handles.figure1,'Visible','off');
This line of code blocks execution of (most) statements until the Visible property of figure1 is off. This includes the execution of the SaveProcessingMethod_OutputFcn which won't occur until the figure has been deleted (via pressing the x button). At this point, handles is empty, and the line of code
varargout{1} = handles.output;
fails because handles is no longer a structure.
The easy fix is to remove the waitfor statement from the SaveProcessingMethod_OpeningFcn function. This will allow the SaveProcessingMethod_OutputFcn to execute normally and there shouldn't be any problems when closing the figure/GUI.
That is the fix, but what was the intent behind including the wait (either waitfor or uiwait)?
You also mention how I added the set(handles.... line since I thought it uses that line to close the window. That line of code will no longer make the GUI/figure visible, but it will still be there. If you want to close it (permanently) then use
delete(handles.figure1);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!