Why does MATLAB think I have 5 output args when I have 6?
이전 댓글 표시
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
Matt
2014년 11월 18일
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.
채택된 답변
추가 답변 (2개)
Ken Atwell
2014년 11월 18일
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
2014년 11월 18일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!