Problem with z value output when computing elevation along a straight line transect

조회 수: 1(최근 30일)
I'm trying to use the compute elevation profile along a straight line code available at:, to determine the elevation (z) along a straight line transect in a fake domain with elevation which goes from -30m to -60m.
However, when I checked the z value I found it is not calculated for the entire straight line transect (it stops at 42.1 degrees but should end at 42.6 degrees).
Does anyone know how to calculate z for the entire straight line?
I have included the code below:
if true
% code
% Fake domain
DDX = 1000; % Varation in the domain size for X
DDY = 2000; % Variation in the domain size for Y
% Elevation -30 to -60 m
Zx = linspace(-30,-60,DDY); % (X) longitudinal bathymetry values
Zy = linspace(-30,-60,DDX); % (Y) latitudinal bathymetry values
Z = meshgrid(Zx,Zy); % Vector Z containing bathymetry values
% Define latitude and longitude of map area
latlim = [41.6, 42.6];
lonlim = [-70.9, -69.9];
% Vectors of latitude and longitude with same interval size as bathymetry
latvec = linspace(latlim(1),latlim(2),DDY);
lonvec = linspace(lonlim(1),lonlim(2),DDX);
% Convert domain to referenced grid using makerefmat function:
dy = abs(latlim(1)-latlim(2))/DDY;
% initial latitude 41.6 minus end latitude 42.6 divided by the number of elements in array DDY
dx = abs(lonlim(1)-lonlim(2))/DDX;
% Specify the coordinates for the left hand corner of the map domain
x11 = lonlim(1);
y11 = latlim(1);
% Create the referenced bathymetry grid needed by mapprofile function
R = makerefmat(x11, y11, dx, dy);
% Input source and end lat/long for straight line transect
sourcelat = 42.0;
sourcelon = -70.8;
endlat = 42.6;
endlon = -70.7;
% Define the endpoints for a straight-line transect through the domain
plat = [sourcelat endlat];
plon = [sourcelon endlon];
% Calculate the change in elevation along the straight line transect
[z,rng,lat,lon] = mapprofile(Z,R,plat,plon);


Amy Haskins
Amy Haskins 2018년 4월 18일
I think the problem is that the referencing matrix isn't quite right. Assuming your grid is regularly spaced in lat/lon, try using georefcells instead to create a referencing object.
R = georefcells(latlim,lonlim,dx,dy);
  댓글 수: 1
Charlotte Findlay
Charlotte Findlay 2018년 5월 4일
Hi Amy,
Thanks for your suggestion! I tried the R = georefcells(latlim,lonlim,dx,dy); and this seemed to run and has created a referencing object, however when I then go to calculate a z value using the code below:
if true
% code
% Define end points of a straight line
plat = [sourcelat endlat];
plon = [sourcelon endlon];
% Calculate the change in bathymetry along the specified transect
[z,rng,lat,lon] = mapprofile(Z,R,plat,plon);
I no longer get an output for z, although I do for rng, lat and lon.
Any idea why this might be?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by