MATLAB Answers

How do i make a line of datapoints between 2 points on map, and use their index for later.

18 views (last 30 days)
I am working with some glaciers in Greenland, where i have a matrix A of data that describes all x,y coordinates and the corresponding ice thickness. What i want is to create a straight line of data points between 2 different chosen x,y coordinates. Then, i want to find the indexes of these x,y points in the original matrix that lie on this straight line, so i can find the corresponding indexes of their respective ice_thickness data points.
The matrix A is a 64164x4 matrix, where the 1st column is the x-coordinates, the 2nd column is the y coordinates, the 3rd column is the height of the bedrock and the 4th column is the height of the ice-surface. So A(:,4)-A(:,3) gives us the ice thickness. This data is for an entire region of greenland, but i only want to find the x,y points along my chosen line, and then the corresponding ice thickness for those data points.
So far i've tried something like this;
a = [400000, -1050000]; %First point
b = [500000, -1115000]; %Second point
x = [a(1), b(1)]; % x-coordinates for our points.
y = [a(2), b(2)]; % y-coordinates for our points.
%We find all x points that lie between our chosen points;
X = a(1):b(1);
%We interpolate for our 2 points with all the points in X, and round.
*Y=interp1(x,y,X)
Y=round(Y)*
X2 = ismember(X,A(:,1)) %We find the indexes of the values in X that corresponds with our x-values in A.
X_A = X(X2) %We make a new vector only with the right indexes.
*Y2 = ismember(Y,A(:,2)) %same approach for Y.
Y_A = Y(Y2)*
%We end up with a vector for Y and X that is both 1x101 in size. This is fine, but i need to find the corresponding ice thickness indexes, for those values that match these x,y values. And this vector of ice thickness must be the same size, because i need to find the flux through this line with the formula below.
*for i=1:length(profilv_z)
*flux(i)=1.0 * profilv_z(i)*0.001 * profilv_dv(i)*0.001 * 0.917 ;*
end
Giga_ton_ice_per_year = sum(flux)*
%where profilv_z is the ice_thickness data. Also, i need to plot the ice_thickness through this line with the script below;
*figure(3)
subplot(2,1,1) * % plot ice_thickness through the flux line;
*plot(Y_A*0.001,profilv_z,'.-') % distance in km.
xlabel('distance in km')
ylabel('ice thickness - meters')*

Accepted Answer

Soumya Saxena
Soumya Saxena on 16 May 2017
You compute the indexes of the values in X that corresponds with the x-values in A. You may consider using scattered interpolation. If x and y are your coordinates in A, i.e. A(:,1) and A(:,2), then let "v" be the thickness , which is the difference between A(:,3) and A(:,4). You can then create a model as:
F = scatteredInterpolant(x,y,v)
Then, you can use this to find thickness at any new query point, xq and yq as follows:
Vq = F(Pq)
Please refer to the following documentation:

More Answers (2)

Soumya Saxena
Soumya Saxena on 9 May 2017
I understand that you want to compute the ice thickness using the third and fourth column. Please let me know why you are performing interpolation to compute Y

Chad Greene
Chad Greene on 7 Jul 2017
There's an example of how to calculate the flux of Thwaites Glacier in Antarctica in the documentation for measures_interp here. Note you can't just multiply the local ice speed by thickness to get the ice flux unless the flux gate is perfectly orthogonal to ice flow.

Community Treasure Hunt

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

Start Hunting!

Translated by