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

12 Ansichten (letzte 30 Tage)
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);
Error in read_mydata (line 41)
Vq = interp2(theta,phi,co_amp_db,10,22);
Error in read_mydata (line 40)
vq = griddata(theta,phi,co_amp_db,10,22)
=======================================
Here is my code
xlx=input_data_file;
sheetname='MAIN';
addpath(pathToOptimizer)
nrow=2002;
ncol=13;
rangero=[1,1,nrow,ncol];
sheetname='Test';
[NUM,TXT,RAW]=readmycells(xlx,rangero,sheetname);
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);

Akzeptierte Antwort

dpb
dpb am 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...
  4 Kommentare
VBBV
VBBV am 22 Jan. 2023
Verschoben: VBBV am 22 Jan. 2023
Check also scatteredInterpolant or griddedInterpolant

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jonas
Jonas am 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)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by