Error using scatteredInterpolant Sample values must be a double array.

Dear all,
I use griddata to interpolate one 2D data. The codes worked quite well half a year. But since today, it always showed an error "Error using scatteredInterpolant. Sample values must be a double array."
Can anyone do me a favor. Thanks a lot.

댓글 수: 5

Sure, we'll try if you let us. If you still have questions, then attach your data and code to read it in and interpolate it with the paperclip icon after you read this:
Yuansen
Yuansen 2025년 11월 26일
편집: Yuansen 2025년 11월 26일
Many thanks for your quick reply. The codes are as following
"
xlin = linspace(min(Xf0), max(Xf0), 100); %%Xf0 is one 1D array
ylin = linspace(min(Yf0), max(Yf0), 100); %%Yf0 is one 1D array
[X,Y] = meshgrid(xlin, ylin);
Z = griddata(Xf0,Yf0,Z0,X,Y,'linear'); %%Z0 is one 1D array.
%%Xf0, Yf0 and Z0 are simutaneously recorded by a DAQ. They have a same length. Xf0 and Yf0 are not %%monolotic.
"
It would help to have Xf0, Yf0 and Z0 as the DAQ returns them.
If everything worked well for a year and there have been no changes (same MATLAB release/version, same DAQ software), something else must have changed.
I can duplicate the error if I pass string values to scatteredinterpolant.
t = linspace(3/4*pi,2*pi,5)';
x = [3*cos(t); 2*cos(t); 0.7*cos(t)];
y = [3*sin(t); 2*sin(t); 0.7*sin(t)];
v = repelem([-0.5; 1.5; 2],length(t));
F = scatteredInterpolant(num2str(x),y,v);
Error using scatteredInterpolant
The input points must be a double array.
Try adding a str2double command to the values returned by your DAQ.
I would use class() on Xf0, Yf0 and Z0 to check that they are in fact class double.

댓글을 달려면 로그인하십시오.

 채택된 답변

Yuansen
Yuansen 2025년 11월 27일
이동: Matt J 2025년 11월 27일
thank you guys! You are all right, the DAQ in this time produced "single" type data. After I define them in "double", the problem was solved.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

질문:

2025년 11월 26일

이동:

2025년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by