Why does MATLAB think I have 5 output args when I have 6?
2 views (last 30 days)
I need help diagnosing this. I have a function that was working when I had 5 output arguments and then I added an output argument and saved it and it no longer works. When I run nargout I get 5 when I clearly have 6. Not sure what is going on here. Please help. code below.
function [RMS_before_YPR,RMS_after_YPR,YPR,totalRMS_before,totalRMS_after,visor_corrected] = visor_comp(visor1,visor2);
%%Save original data, sort and match data
[visor1,visor2] = organize_data(visor1,visor2);
%%Create and apply geometric transformation (YPR) to visor1
RMS_before_YPR = (sqrt(sum((visor2-visor1).^2)./num).*pi./180).*1e3;
RMS_after_YPR = (sqrt(sum((visor2-visor_corrected).^2)./num).*pi./180).*1e3;
Adam on 18 Nov 2014
Edited: Adam on 18 Nov 2014
Have you used mlock on the file at all?
Your comment below shows it thinks you have too many arguments when you call it, i.e. it is still expecting just 5 output arguments.
mislocked( visor_comp );
If it returns 1 then type
munlock( visor_comp );
If it doesn't return true then just try:
and if that doesn't work try restarting Matlab. I have occasionally had old things hang around in memory (though usually classes rather than functions) until I restart Matlab.
More Answers (2)
Ken Atwell on 18 Nov 2014
Do you mean that you are calling nargout from within the function, maybe inside the debugger? If so, nargout will be the number of outputs the caller is capturing, not the total number that could be returned. It works this way so a function can avoid computing an output argument that the caller is not capturing.
'nargout' would be 2 in this case:
>> [a,b] = visor_comp(0,0)
So, check where you are calling this code from and be sure you're capturing all six output.
Matt on 18 Nov 2014
A) Make sure that when you call the function, you are asking for all 6 outputs. nargout tells you the number of outputs asked for - not the number of outputs available.
B) Make sure you define your outputs in all execution paths. Right now if visor1 is empty then visor_corrected is never populated.