dot indexing not supported by variable of this type

2 ビュー (過去 30 日間)
Maithili Pathak
Maithili Pathak 2020 年 7 月 17 日
コメント済み: Arthur Roué 2020 年 7 月 23 日
function [lon, lat, h] = Geodetic(r)
global const
R_equ = const.R_Earth;
f = const.f_Earth;
epsRequ = eps*R_equ; % Convergence criterion
e2 = f*(2-f); % Square of eccentricity
X = r(1); % Cartesian coordinates
Y = r(2);
Z = r(3);
rho2 = X*X + Y*Y; % Square of distance from z-axis
% Check validity of input data
if (norm(r)==0)
disp ( ' invalid input in Geodetic constructor\n' );
lon = 0;
lat = 0;
h = -const.R_Earth;
return
end
% Iteration
dZ = e2*Z;
while(1)
ZdZ = Z + dZ;
Nh = sqrt ( rho2 + ZdZ*ZdZ );
SinPhi = ZdZ / Nh; % Sine of geodetic latitude
N = R_equ / sqrt(1-e2*SinPhi*SinPhi);
dZ_new = N*e2*SinPhi;
if (abs(dZ-dZ_new) < epsRequ)
break
end
dZ = dZ_new;
end
% Longitude, latitude, altitude
lon = atan2(Y, X);
lat = atan2(ZdZ, sqrt(rho2));
h = Nh - N;
Dot indexing is not supported for variables of this type.
Error in Geodetic (line 13)
R_equ = const.R_Earth;

回答 (1 件)

Arthur Roué
Arthur Roué 2020 年 7 月 17 日
編集済み: Arthur Roué 2020 年 7 月 17 日
Your variable const is a global one. First of all, use of global variables is widely not reccomended, read this article for more details : https://fr.mathworks.com/help/matlab/matlab_prog/share-data-between-workspaces.html.
Then, if your global variable const is not defined (e.g. first call of your function), the line
global const
will initialize it with an empty double. Then you have to initialize it as a struct if you want to call it this way (with dot indexing).
global const
if isempty(const)
const = struct('R_Earth', yourVal, 'f_Earth', yourVal)
end
  1 件のコメント
Arthur Roué
Arthur Roué 2020 年 7 月 23 日
Did it work for you ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by