Why does MATLAB think I have 5 output args when I have 6?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
% orig1=visor1;
% orig2=visor2;
[visor1,visor2] = organize_data(visor1,visor2);
%%Create and apply geometric transformation (YPR) to visor1
if isempty(visor1)
% [RMS_before_YPR,RMS_after_YPR,YPR,totalRMS]
RMS_before_YPR=0;
RMS_after_YPR=0;
YPR=0;
totalRMS_before=0;
totalRMS_after=0;
else
num=length(visor1);
tform=fitgeotrans(visor1,visor2,'nonreflectivesimilarity');
rot_cos=tform.T(1,1);
rot_sin=tform.T(2,1);
roll=atan2d(rot_sin,rot_cos);
yaw=tform.T(3,1);
pitch=tform.T(3,2);
visor_corrected=transformPointsForward(tform,visor1);
RMS_before_YPR = (sqrt(sum((visor2-visor1).^2)./num).*pi./180).*1e3;
sum_of_sqs1=sum((visor2(:,1)-visor1(:,1)).^2+(visor2(:,2)-visor1(:,2)).^2)./num;
totalRMS_before=(sqrt(sum_of_sqs1).*(pi/180)).*1e3;
RMS_after_YPR = (sqrt(sum((visor2-visor_corrected).^2)./num).*pi./180).*1e3;
sum_of_sqs2=sum((visor2(:,1)-visor_corrected(:,1)).^2+(visor2(:,2)-visor_corrected(:,2)).^2)./num;
totalRMS_after=(sqrt(sum_of_sqs2).*(pi/180)).*1e3;
YPR=[yaw,pitch,roll];
end
1 comentario
Matt
el 18 de Nov. de 2014
Alex,
The code seems to run and nargout returns a value of 6 if six outputs are in the calling statement.
Two things.
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.
Respuesta aceptada
Adam
el 18 de Nov. de 2014
Editada: Adam
el 18 de Nov. de 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.
Type
mislocked( visor_comp );
If it returns 1 then type
munlock( visor_comp );
If it doesn't return true then just try:
clear all;
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.
Más respuestas (2)
Ken Atwell
el 18 de Nov. de 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.
0 comentarios
Matt
el 18 de Nov. de 2014
Alex,
Two things.
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.
Ver también
Categorías
Más información sobre Argument Definitions 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!