call variable from next function

Hi, im confused when i have a variable described in the second function, but recently i need the variable to used in first function. How can I do this? Anyone help me please.
This is my firts function, here i need the value of variabel B:
function cylindrical
%Parameter ellipsoid WGS84
a= 6378137;
b= 6356752.3;
E =((a^2)-(b^2))/(a^2);
N=a./(sqrt(1-((E^2)*(sin(deg2rad(B)).^2))));
M=a.*(1-(E^2))./((1-(E^2)*(sin(deg2rad(B).^2))).^(2/3));
%
% Tissot distortion ellipses (indicatrix)
jacobi=['d',projection];
dphi=30;dlam=30; % Spacing between parallels and meridians for Tissot ellipses
phi=-60:dphi:60;
lam=-180+dlam:dlam:180-dlam;
for i=1:length(phi)
Phi=phi(i);
G=[(N^2)*(cos(deg2rad(B))^2),0;0,(M^2)]; % Metric (matrix) of the ellipsoid (Radius = 1)
for j=1:length(lam)
J=feval(jacobi,Phi,lam(j)); % Jacobian matrix of the mapping equations
C=J'*g*J; % based on unit metric (matrix) of the chart: g=eye(2)
end
Here my second function that describe the variabel B:
function [x,y]=cylindrical(B,L,const)
n < 2
error('Cylindrical needs at least two arguments');
end
if nargin == 3
R=const;
else
%Parameter WGS84
a= 6378137;
b= 6356752.3;
E =((a^2)-(b^2))/(a^2);
N=a./(sqrt(1-((E^2)*(sin(deg2rad(B)).^2))));
M=a.*(1-(E^2))./((1-(E^2)*(sin(deg2rad(B).^2))).^(2/3));
end
%
B=B(:);L=L(:);
if length(B) ~= length(L)
[L,B]=meshgrid(L,B);
end

2 comentarios

KALYAN ACHARJYA
KALYAN ACHARJYA el 11 de En. de 2021
You have to call the second function (From the main script) by passing inputs, B,L and const, which evaluates the x and y values
Adam Danz
Adam Danz el 11 de En. de 2021
You can't have two functions with the same name.
Secondly, B is both an input and an internal variable that overwrites the input. That makes no sense.
Lastly, the final definition of B is [L,B]=meshgrid(L,B); which uses L and B which are both inputs so this can be computed outside of the function.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Geoscience en Centro de ayuda y File Exchange.

Preguntada:

el 11 de En. de 2021

Comentada:

el 11 de En. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by