varargout isn't working for output from GUI when same formatting works just fine in similar GUI
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to get output from a GUIDE GUI by passing back to the calling data analysis script and when I press the finish button in my gui it completes uiresume(handles.object) which was previously set by uiwait(handles.object).
Then it gets to the following section.
function varargout = GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(nargout)
if handles.done==1
handles.output={handles.value1,handles.value2};
% Get default command line output from handles structure
varargout = handles.output;
delete(hObject)
end
It then gives me the error:
Too many output arguments.
despite calling with this
[output1,output2]=GUI(input1(:,m),input2(:,m));
output1 and output2 are both non-array doubles and the
The above functions, in the end, also don't close the GUI despite calling for delete(hObject) and when I use the actual exit window button it causes the error
Error while evaluating CloseRequestFcn
and it tells me
??? Error using ==> plot
Error in color/linetype argument
as part of the same CloseRequestFcn error when I never even use color/linetype arguments in this GUI.
Then because of the CloseRequestFcn error I'm never able to reinitialize the same GUI until after I close out of the Matlab session which if I click the exit button cause Matlab to enter an infinite loop preventing it from closing and forcing me to use Ctr+Alt+Delete to exit.
What is most infuriating about this is that I have used the same format for opening and closing a similar GUI from a similar script that fully functions. Actually the previous GUI was copied and pasted and altered to fit the requirements. The process of me passing variables back is exact same to, the only difference is that I was passing two arrays in the original GUI instead of two non-array doubles. However the "Done" button and its callback function have not changed nor did the OutputFcn
The "Done" button callback is as follows
% --- Executes on button press in complete.
function complete_Callback(hObject, eventdata, handles)
% hObject handle to complete (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.done=1;
handles=guidata(hObject);
guidata(hObject,handles);
uiresume(handles.object);
What is happening? How do I fix it?
I thank anyone and everyone who can help in advance.
0 comentarios
Respuestas (2)
Adam
el 19 de Nov. de 2015
Unless I am missing something you only assign 1 output argument (one cell array of two cells):
handles.output={handles.value1,handles.value2};
so calling it asking for two output arguments would give you that message.
Off the top of my head I can't actually think how you assign more than one output argument. I rarely use output arguments from a GUI, but when I do I think I just output one variable that contains all the outputs I want - e.g. a struct or an array or whatever is appropriate.
Do you need two distinct outputs or can you just have the one output and then interrogate the cells of that output afterwards to divide it up if required?
6 comentarios
Stephen23
el 20 de Nov. de 2015
Editada: Stephen23
el 20 de Nov. de 2015
Perhaps the problem is really your if operator means that there are some instances where the callback is called but the if does not run and so varargout has not values to return (it defaults to empty). Try putting an else case to define varagout for those cases:
if handles.done==1
....
else
varargout = cell(1,nargout);
end
0 comentarios
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!