フィルターのクリア

Find distance of two points inside a matrix

2 ビュー (過去 30 日間)
lena kappa
lena kappa 2023 年 6 月 7 日
コメント済み: lena kappa 2023 年 6 月 8 日
Hello everyone! So I have a meshgrid of x and y and an other matrix that gives me the z corresponding to the same indexes.I want to choose an x1,y1 value and an x2,y2 value and interpolate all the z in between those to coordinates?How can I do this?
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 6 月 7 日
Check out interp2
lena kappa
lena kappa 2023 年 6 月 8 日
Thank you

サインインしてコメントする。

採用された回答

Kautuk Raj
Kautuk Raj 2023 年 6 月 8 日
The interp2 function in MATLAB to interpolate the depths between two points on a grid of longitudes and latitudes. I will show an example here:
% Create a meshgrid of longitudes and latitudes
lon = linspace(-180, 180, 361);
lat = linspace(-90, 90, 181);
[lon_grid, lat_grid] = meshgrid(lon, lat);
% Create a matrix of depths corresponding to the grid
depths = rand(size(lon_grid));
% Choose two points to interpolate between
x1 = -100;
y1 = 30;
x2 = 50;
y2 = 60;
% Interpolate the depths between the two points
interp_lon = linspace(x1, x2, 100);
interp_lat = linspace(y1, y2, 100);
interp_depths = interp2(lon_grid, lat_grid, depths, interp_lon, interp_lat);
% Plot the original depths and the interpolated depths
figure
subplot(2, 1, 1)
pcolor(lon_grid, lat_grid, depths)
shading interp
hold on
plot(x1, y1, 'r.', x2, y2, 'r.')
colorbar
title('Original Depths')
xlabel('Longitude')
ylabel('Latitude')
subplot(2, 1, 2)
plot(interp_lon, interp_depths, 'r')
hold on
plot(lon_grid, depths, 'b')
legend('Interpolated Depths', 'Original Depths')
title('Interpolated Depths')
xlabel('Longitude')
ylabel('Depth')
The output looks like:
  1 件のコメント
lena kappa
lena kappa 2023 年 6 月 8 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by