From: David O'Connor on
Hello there,

I'm new to programming and matlab and can't figure out why this script won't run. I saved the script as plate_vel.m. When I try to run it, it says input argument "lat" is undefined. Here's the script.

function v1 = plate_vel(lat, lon, latp, lonp, omega)
%
%computes the local velocity plate vector given position and
% Euler Pole position and velocity
%
%INPUT:
%
% lat, lon - position where you want local vector
% latp, lonp, omega - Euler pole position and velocity
% lat and lon are in degrees
% omega is in degrees/My
%
%
%OUTPUT:
%
% v1 = [vn,ve,vd]' velocity in north, east, and down directions
% (referred to point p) in mm/yr
%
R_earth = 6380e6; %radius of earth in millimeters
%
%
%
%
%convert from degrees to radians
deg_to_radians = pi / 180;
lat = lat*deg_to_radians;
lon = lon*deg_to_radians;
latp = latp*deg_to_radians;
lonp = lonp*deg_to_radians;
%
omega = omega*1e-06*(pi/180);%convert to radians per year (from degrees/My)
%
%convert to cartesian coordinates
%
P = [cos(lat)*cos(lon), cos(lat)*sin(lon), sin(lat)]';
EP = [cos(latp)*cos(lon), cos(latp)*sin(lonp), sin(latp)]'*omega;
%
%compute the cross product: EP X P
VC = R_earth*cross(EP,P);
%rotate to local coordinates
%
T = zeros(3,3);
T(1,1) = -sin(lat)*cos(lon);
T(1,2) = -sin(lat)*sin(lon);
T(1,3) = cos(lat);
%
T(2,1) = -sin(lon);
T(2,2) = cos(lon);
T(2,3) = 0;
%
T(3,1) = -cos(lat)*cos(lon);
T(3,2) = -cos(lat)*sin(lon);
T(3,3) = -sin(lat);

v1 = T*VC;
%Now I try this input:
plate_vel(37,-123,48.7,-78.2,0.78)

%and it says lat is undefined.
From: TideMan on
On Apr 20, 8:56 pm, "David O'Connor" <oconnor.davi...(a)gmail.com>
wrote:
> Hello there,
>
> I'm new to programming and matlab and can't figure out why this script won't run.  I saved the script as plate_vel.m.  When I try to run it, it says input argument "lat" is undefined.  Here's the script.
>
> function v1 = plate_vel(lat, lon, latp, lonp, omega)
> %
> %computes the local velocity plate vector given position and
> %   Euler Pole position and velocity
> %
> %INPUT:  
> %
> %        lat, lon  - position where you want local vector
> %        latp, lonp, omega - Euler pole position and velocity
> %        lat and lon are in degrees
> %        omega is in degrees/My
> %
> %
> %OUTPUT:
> %
> %        v1 = [vn,ve,vd]' velocity in north, east, and down directions
> %                         (referred to point p) in mm/yr
> %
> R_earth = 6380e6; %radius of earth in millimeters
> %
> %
> %
> %
> %convert from degrees to radians
> deg_to_radians = pi / 180;
> lat = lat*deg_to_radians;
> lon = lon*deg_to_radians;
> latp = latp*deg_to_radians;
> lonp = lonp*deg_to_radians;
> %
> omega = omega*1e-06*(pi/180);%convert to radians per year (from degrees/My)
> %
> %convert to cartesian coordinates
> %
> P = [cos(lat)*cos(lon), cos(lat)*sin(lon), sin(lat)]';
> EP = [cos(latp)*cos(lon), cos(latp)*sin(lonp), sin(latp)]'*omega;
> %
> %compute the cross product: EP X P
> VC = R_earth*cross(EP,P);
> %rotate to local coordinates
> %
> T = zeros(3,3);
> T(1,1) = -sin(lat)*cos(lon);
> T(1,2) = -sin(lat)*sin(lon);
> T(1,3) = cos(lat);
> %
> T(2,1) = -sin(lon);
> T(2,2) = cos(lon);
> T(2,3) = 0;
> %
> T(3,1) = -cos(lat)*cos(lon);
> T(3,2) = -cos(lat)*sin(lon);
> T(3,3) = -sin(lat);
>
> v1 = T*VC;
> %Now I try this input:
> plate_vel(37,-123,48.7,-78.2,0.78)
>
> %and it says lat is undefined.

Type this:
which plate_vel
and tell us what it says.

I suspect you have another version of plate_vel hanging around that is
further up the pathlist than the one you are working on.
 | 
Pages: 1
Prev: int32 to double
Next: return to begin of function