varargout isn't working for output from GUI when same formatting works just fine in similar GUI

6 visualizaciones (últimos 30 días)
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.

Respuestas (2)

Adam
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
Michael VanderWal
Michael VanderWal el 20 de Nov. de 2015
I did something to see if it would prevent the GUI from trying to to reopen.
I put this ---
if getappdata(0,'initiationvalue') == 1
delete(hObject)
end
in the opening function, and this ---
handles.done=1;
setappdata(0,'initiationvalue',1)
guidata(hObject,handles);
uiresume(handles.HIB);
in the callback for the "Done" button.
This prevents the following error from showing up.
??? Error using ==> plot
Error in color/linetype argument
and the error from
handles.torque=varargin{1};
which was
Index exceeds matrix dimensions.
The original problem shouldn't be a problem in the calling script even if it was a loop because it would still have to pass all the same variables back to the GUI because they aren't deleted in the GUI or the script. Even so, my code shouldn't cause the GUI to appear more than once for the same set of data. The GUI by the way is for hand selection of data that was missed by the automated data analysis performed by the script. So I don't know my GUI tries reinitialize, but I figured out how to bypass it.
Michael VanderWal
Michael VanderWal el 20 de Nov. de 2015
Using deal() worked. And I figured out why, my program kept trying to re-loop.
I still don't know why not using deal() worked in my other GUI though, which really is the original problem. What is different about the the way I tried passing variables in this GUI from the way I did in the original when as far as I know they aren't?

Iniciar sesión para comentar.


Stephen23
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

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by