Error using matlab.internal.math.interp1 The sample points must be finite.
22 views (last 30 days)
Show older comments
huiting wang
on 22 Apr 2022
Commented: Bob photonics
on 14 Feb 2025
when I ran a script,
for i=1:sz(2)
tOut(:,i) = interp1(x(:,i),v(:,i),xq(:,i));
end
I got those errors
Error using matlab.internal.math.interp1
The sample points must be finite.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in coolprop_tab.MoistAir.calcMoistHeatCool (line 782)
tOut(:,i) = interp1(x(:,i),v(:,i),xq(:,i));
4 Comments
Accepted Answer
Steven Lord
on 26 Apr 2022
Error in coolprop_tab.MoistAir.calcMoistHeatCool (line 783)
tOut(:,i) = interp1(x(:,i),v(:,i),xq(:,i));
Set a breakpoint on line 783 of coolprop_tab.MoistAir.calcMoistHeatCool or set an error breakpoint (which doesn't require you to specify a line number.) Then run your code. Once MATLAB stops at the breakpoint, show us what these commands return:
locationOfNonfiniteX = find(~isfinite(x(:, i)))
locationOfNonfiniteV = find(~isfinite(v(:, i)))
locationOfNonfiniteXq = find(~isfinite(xq(:, i)))
At least one of those variables should be non-empty. Look at the values of x, v, and/or xq at those locations and you should find they are either Inf or NaN. Once you've identified the problem locations, you'll need to work your way back through your code to determine where and why the nonfinite values were introduced.
Inf likely came in from an overflow; if you multiplied an extremely large number by another number the result could be greater than realmax.
NaN likely would come from dividing 0 by 0 or subtracting Inf from Inf. There are other ways that you can get a NaN but those are two of the more common.
3 Comments
Steven Lord
on 27 Apr 2022
I'm guessing this code is in a loop. If so, keep running until you find the column of x, v, and/or xq that has the nonfinite data.
More Answers (1)
huiting wang
on 27 Apr 2022
2 Comments
Bob photonics
on 14 Feb 2025
Use this code to look for NaN/Inf values in your matrix/array/table
~isfinite(YourMatrix) %if it shows a logical 1 then you've a NaN/Inf value
[row, col] = find(~isfinite(YourMatrix)) % will show you all the locations where you have NaN values
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!