Locating z-values at certain x-values
조회 수: 4 (최근 30일)
이전 댓글 표시
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);
댓글 수: 0
채택된 답변
Star Strider
2021년 10월 21일
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.
.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!