# Locating z-values at certain x-values

3 views (last 30 days)
Christian Mathiesen on 21 Oct 2021
Answered: Star Strider on 21 Oct 2021
Hi.
I have a 3643x3 matrix containing x and y positions, as well as depth of seafloor depth along a seismic line in the Greenland Sea (seadepth_073852). I'm trying to create a matrix containing z-values at the x-values contained in the x-array.
I've tried using
k = find(x==x(:))
z_sea(k)
but obviously that only creates an index, and I get the first 35 entries from z_sea. However, I need the specific values at the x-values.
x = tykkelse_073852(:,1);
z = tykkelse_073852(:,3);

Star Strider on 21 Oct 2021
I am not certain what the desired result is, sp[ecifically finding the ‘z’ values that correspond to ‘x_sea’ or the reverse.
Try this —
x = tykkelse_073852(:,1);
z = tykkelse_073852(:,3);
x_sea = seadepth_073852(:,1); % Need This Vector To Do The Interpolation
[Uxz_sea,ia,ic] = unique([x_sea z_sea],'rows');
x_sea = Uxz_sea(:,1);
z_sea = Uxz_sea(:,2);
% zr = [min(z) max(z); min(z_sea) max(z_sea)] % 'z' Values Are An Order-Of-Magnitude Different
figure
yyaxis left
plot(x, z)
ylabel('tykkelse\_073852')
yyaxis right
plot(x_sea, z_sea)
grid
zi = interp1(x_sea,z_sea, x);
figure
plot(x_sea, z_sea)
hold on
plot(x, zi, 'sr')
hold off
grid
xlabel('x\_sea')
ylabel('z, z\_sea')
title('Interpolated Values')
To get the reverse (interpolating ‘x’ and ‘z’ with respect to ‘x_sea’), just reverse the arguments to interp1.
.

### Categories

Find more on Matrices and Arrays in Help Center and File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!