Clear Filters
Clear Filters

Interpolating a 3x3 matrix to produce a 5x5 matrix

15 views (last 30 days)
I have a 3x3 matrix with data in the corners and in the center, and unkown in the remaining 4 entries. I would like to expand the 3x3 into a 5x5 by making the corners the max/min for the x and y axis and using the "5-point" matrix to interpolate the data in the intervals in between. So far, I can only make interp2 solve for the off-diagonal.
%have data where y is a vector of altitude and x is a vector of speed.
% b in this case is max altitude and max speed
%d is min altitude and min speed
data = [a u b;
u c u;
d u e];
%want
intpdata = [a i1 i2 i3 b;
i4 i5 i6 i7 i8
i9 i10 c i11 i12
i13 i14 i15 i16 i17
d i18 i19 i20 e];
My initial guess was to use interp1 on individual rows and columns on the remaining unknown (i2,i9,i12,and i19) from "data" and then use those results to interpolate the remaining intervals by sectioning them off in 3x3s (also with interp1).
%Have new data where u# is a value interpolated from the 3x3 using interp1
intpdata = [a i1 u1 i3 b;
i4 i5 i6 i7 i8
u2 i10 c i11 u3
i13 i14 i15 i16 i17
d i18 u4 i20 e];
%further interpolate to solve for the i#s
intpdata_1 = [a i1 u1;
i4 i5 i6;
u2 i10 c]
intpdata_2 = [u1 i3 b;
i6 i7 i8
c i11 u3]
%and so on...
is there a more efficient way?
(the 3x3 is actually a cell with 30x50 matrix in each cell where the rows are correlated data, but I believe the method should act similar regardless of of singular or matrix)
Thank you

Accepted Answer

Chunru
Chunru on 9 Jun 2021
% Define the coordinate of the five points (corners and center)
x = [1 5 3 1 5]';
y = [1 1 3 5 5]';
z = rand(5, 1); % data at these points
% Interpolation
F = scatteredInterpolant(x, y, z); % interpolant
[xq, yq] = meshgrid(1:5, 1:5); % regular grid 5x5
zq = F(xq, yq); % z at the regular grid
% Show the original and interpolated data
figure;
scatter3(x, y, z); hold on
mesh(xq, yq, zq);

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!