2017-11-18 467 views
-3

這是我的功能。在調用期間未分配輸出參數:MATLAB錯誤

function [ phi, lambda, h ] = trans_cartesian(x, y, z) 
    a=6378137; 
    b=6356752.3141; 
    e2=(a^2-b^2)/(a^2); 
    lambda= atand(y/x); 
    P= sqrt(x^2+y^2); 


    phi=atand((z/P)/(1-(e2))); 
    while phi< 10^-12; 
     N= a/sqrt(1-(e2).*(sind(phi))^2); 
     h= (P/cosd(phi))-N; 
     phi=atand((z/P)/(1-(N/N+h).*(e2)));  
    end 

有關如何解決此問題的任何想法? 這是實際的錯誤消息:

輸出參數 「H」(或其它)呼叫期間未分配 「C:\ trans_cartesian.m> trans_cartesian」。

回答

2

正如您在錯誤中提到的,在某些情況下while循環的條件不正確。而你的代碼必須返回h的值。所以,你應該至少在你的代碼中爲h設置一個初始值。例如:

function [ phi, lambda, h ] = trans_cartesian(x, y, z) 
h = 0 
% continue 

或者,把while後一個條件,如果循環的條件是不正確的,取代的h值到特定值:

function [ phi, lambda, h ] = trans_cartesian(x, y, z) 
%your code 
while phi<10^-12 
    % your code 
end 
if(phi > 10^-12) 
    h = 0; % or specified value 
end 
相關問題