Locating z-values at certain x-values

2 visualizzazioni (ultimi 30 giorni)
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.
Thank you in advance, hope I made the problem clear.
tykkelse_073852 = load("tykkelse_073852.txt");
seadepth_073852 = load('seafloor_depth_073852.txt');
x = tykkelse_073852(:,1);
z = tykkelse_073852(:,3);
z_sea = seadepth_073852(:,3);

Risposta accettata

Star Strider
Star Strider il 21 Ott 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 —
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.
.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Tag

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by