# How to interpolate a set of data wher the X size is different for the Y size

38 views (last 30 days)
Robert Jones on 21 Jan 2023
Commented: Robert Jones on 22 Jan 2023
Hello,
I have a set of data X (size=2001,1) and Y (size=3,1). The Z matrix size is (2001,3). X and Y have uniform increments by the X size is not the same as the size of Y.
Can I use meshgrid or interp2? I tried but I got errors
for meshgrid
Error using griddata
The lengths of X and Y must match the size of Z.
for interp2
Error using griddedInterpolant
Sample points vector corresponding to grid dimension 1 must contain 3 elements.
Error in interp2>makegriddedinterp (line 226)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 126)
F = makegriddedinterp({X, Y}, V, method,extrap);
Vq = interp2(theta,phi,co_amp_db,10,22);
vq = griddata(theta,phi,co_amp_db,10,22)
=======================================
Here is my code
xlx=input_data_file;
sheetname='MAIN';
nrow=2002;
ncol=13;
rangero=[1,1,nrow,ncol];
sheetname='Test';
phi=NUM(1,3:4:ncol)';
theta=NUM(2:nrow,1);
nnp=size(phi);
nnt=size(theta);
np=nnp(2);
nt=nnt(1);
co_amp_db=NUM(2:nrow,2:4:ncol);
co_phase_db=NUM(2:nrow,3:4:ncol);
cx_amp_db=NUM(2:nrow,4:4:ncol);
cx_phase_db=NUM(2:nrow,5:4:ncol);
vq = griddata(theta,phi,co_amp_db,10,22);
Vq = interp2(theta,phi,co_amp_db,10,22);

dpb on 21 Jan 2023
x=1:10;y=1:3; % coarse spacing
z=rand(numel(x),numel(y));
surf(y,x.',z)
hold on
Z=interp2(y,x.',z,1:0.5:3,[1:0.5:10].'); % increase spacing by half...
surf(1:0.5:3,[1:0.5:10].',Z); % plot on top... Robert Jones on 22 Jan 2023
Thank you

Jonas on 21 Jan 2023
you can usw meshgrid to prepare your xq and yq:
Y=9:13;X=1:2:5;Z=rand(5,3);
[xq,yq]=meshgrid(1:0.5:5,9:0.5:13);
interp2(X,Y,Z,xq,yq)
Robert Jones on 22 Jan 2023
Thank you

### Categories

Find more on Interpolation in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!