How to do interpolation in matlab??

I have attached an excel file, which contains x, y, z data. I want to interpolate the data. Can you help?? (In the data for a particular x at different y value, the z value is different. )

 采纳的回答

I am not absolutely certain what you want to do.
The row lengths between unique values in the first column are not the same, so using reshape is not an option to create matrices from the data.
One option, if you want to create a uniformly-sampled matrix, is to use griddata to do the interpolation:
D = readmatrix('data.xlsx');
[Du,ia] = unique(D(:,1));
rowlen = diff(ia); % Changes In ‘x’
xv = linspace(min(D(:,1)), max(D(:,1)), 50);
yv = linspace(min(D(:,2)), max(D(:,2)), 50);
[X,Y] = ndgrid(xv,yv);
Z = griddata(D(:,1), D(:,2),D(:,3),X,Y);
figure
surf(X, Y, Z)
This also plots the result.
Change the code appropriately to get the result you want.

8 个评论

Can i make it an 2d interpretation instead of 3d??
Means I want to represent it in a plane not as a 3d surface
It was not initially obvious what result you wanted.
It is straightforward to change the resolution of the interpolation:
N = 250;
xv = linspace(min(D(:,1)), max(D(:,1)), N);
yv = linspace(min(D(:,2)), max(D(:,2)), N);
[X,Y] = ndgrid(xv,yv);
Z = griddata(D(:,1), D(:,2),D(:,3),X,Y);
with ‘N’ the same or different for each linspace call, depending on what you want.
With respect to plotting, one option:
figure
surf(X, Y, Z)
shading('interp')
view(0,90)
Another option is to change the surf call to contourf:
contourf(X, Y, Z, 'EdgeColor','none')
Experiment to get the result you want.
can i do kriging interpolation??
Thank you. The problem I am facing is that I am not getting interpolated data in all the range.
As always, my pleasure!
I am not certain what to suggest with respect to getting all the information you want from your data, since I am not certain what that is.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Interpolation 的更多信息

产品

版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by