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 —
tykkelse_073852 = readmatrix("https://www.mathworks.com/matlabcentral/answers/uploaded_files/774128/tykkelse_073852.txt");
seadepth_073852 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/774123/seafloor_depth_073852.txt');
x = tykkelse_073852(:,1);
z = tykkelse_073852(:,3);
x_sea = seadepth_073852(:,1); % Need This Vector To Do The Interpolation
z_sea = seadepth_073852(:,3);
[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)
ylabel('seadepth\_073852')
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')
legend('tykkelse\_073852','Interpolated seadepth\_073852', 'Location','best')
title('Interpolated Values')
To get the reverse (interpolating ‘x’ and ‘z’ with respect to ‘x_sea’), just reverse the arguments to interp1.
.