How to interpolate in 3d?

42 ビュー (過去 30 日間)
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar 2019 年 2 月 18 日
コメント済み: Akira Agata 2019 年 2 月 21 日
I have a matrix in 100 distane and 10 distance which i want to interpolate to 1
but as it is a matrix i want to interpolate in 3D
I have tried it interpolating in 2D and getting some irregularities in the which can be seen in attached picture
The 2D code is as follows
[num] = xlsread('Mappe2.xlsx') ;
n = 860;
num1=num(2:87,2:26)';
B = interp1(1:size(num1, 2), num1.', linspace(1, size(num1, 2), n));
n = 250;
B1 = interp1(1:size(B, 2), B.', linspace(1, size(B, 2), n));
surf(1:860,1:250,B1,'edgecolor','none');
How to code further to avoid these irregularities?
I have also attached the Excel file feom the code
forum.PNG

採用された回答

Akira Agata
Akira Agata 2019 年 2 月 19 日
You can use scatteredInterpolant to do this task. The following is an example.
% Read data file
Data = xlsread('Mappe2.xlsx') ;
% Adjust data to grid data format
x = Data(1,2:end);
y = Data(2:end,1);
[xGrid,yGrid] = meshgrid(x,y);
zGrid = Data(2:end,2:end);
% Apply scatteredInterpolant function
idx = isnan(zGrid(:));
F = scatteredInterpolant(xGrid(~idx),yGrid(~idx),zGrid(~idx),...
'linear','linear');
% Interpolation (linear) and Extrapolation (linear)
zGridInterp = F(xGrid,yGrid);
% Show the result
figure
surf(xGrid,yGrid,zGridInterp,...
'EdgeColor', 'none',...
'FaceColor', 'interp')
view(2)
colorbar
surf.png
  4 件のコメント
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar 2019 年 2 月 21 日
no i want x=1:1:8500 and y=1:1:240
Akira Agata
Akira Agata 2019 年 2 月 21 日
OK, that's a piece of cake.
I have slightly modified to do that. I hope this will be some help!
% Read data file
Data = xlsread('Mappe2.xlsx');
Data = Data';
% Adjust data to grid data format
x = Data(1,2:end);
y = Data(2:end,1);
[xGrid, yGrid] = meshgrid(x,y);
zGrid = Data(2:end,2:end);
% Apply scatteredInterpolant function
idx = isnan(zGrid(:));
F = scatteredInterpolant(xGrid(~idx),yGrid(~idx),zGrid(~idx),...
'linear','linear');
% New grid
[xGrid2, yGrid2] = meshgrid(1:8500,1:240);
% Interpolation (linear) and Extrapolation (linear)
zGridInterp = F(xGrid2,yGrid2);
% Show the result
figure
surf(xGrid2,yGrid2,zGridInterp,...
'EdgeColor', 'none',...
'FaceColor', 'interp')
view(2)
colorbar
surf2.png

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

その他の回答 (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