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: https://uk.mathworks.com/help/map/data-grid-values-along-a-path.html, 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: https://uk.mathworks.com/help/map/ref/makerefmat.html
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);
end

回答(1 个)

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
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);
end
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