Error using matlab.int​ernal.math​.interp1 The sample points must be finite.

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

Attach your data x, v and xq. It seems there is a problem with the data.
here is the part of x,v and xq, I put the whole function below
%%
x = -(mDry .* (hDryIn - hDryOut) + ...
mVapIn .* hVapIn - mVapOut .* hVapOut + ...
mWatIn .* hWatIn - mWatOut .* hWatOut);
v = FOut.t;
if isvector(Q)
xq = Q;
else
xq = cumsum(Q);
end
for i=1:sz(2)
tOut(:,i) = interp1(x(:,i),v(:,i),xq(:,i));
end
%%
%%%%%The whole function is:
function tOut = calcMoistHeatCool(mFlow,Q,HeatOrCool,varargin)
% Calculates the new temperature of a Moist Air fluid, depending on
% the amount of heating or cooling is provided.
%
%
sz = size(Q);
if nargin == 4
FIn = varargin{1};
FOut = FIn.copy();
elseif nargin == 6
pIn = varargin{1};
tIn = varargin{2};
X_totIn = varargin{3};
FIn = coolprop_tab.MoistAir('p',pIn,'t',tIn,'X_tot',X_totIn);
FOut = FIn.copy();
end
switch lower(HeatOrCool)
case 'heating'
Q = abs(Q);
case 'cooling'
Q = -abs(Q);
end
% Save the initial enthalpy of the dry air, vapour and water
hDryIn = FIn.h_dry_air;
hVapIn = FIn.h_vapor;
hWatIn = FIn.h_water;
cpDryIn = FIn.cp_dry_air;
if isvector(Q)
tMax = FIn.t + sum(Q,2)./(mFlow * cpDryIn);
else
tMax = FIn.t + sum(Q,1)./(mFlow * cpDryIn);
end
% Define dry air, vapour and water mass flows from total mass
% flow
XwatIn = FIn.X_tot - FIn.Xs; XwatIn(XwatIn < 0) = 0;
mDry = mFlow ./(1 + FIn.X + XwatIn);
mVapIn = mDry .* FIn.X;
mWatIn = mDry .* XwatIn;
% Initialise tOut
tOut = zeros(sz);
% Update FOut
k = 1000; oi = ones(k,numel(FIn.p));
p_ = oi.*FIn.p;
X_tot_ = oi.*FIn.X_tot;
t_ = oi;
for i=1:sz(2)
t_(:,i) = linspace(FIn.t(i),tMax(i),1000);
end
FOut.updateFluid('p',p_,'t',t_,'X_tot',X_tot_);
hDryOut = FOut.h_dry_air;
hVapOut = FOut.h_vapor;
hWatOut = FOut.h_water;
XwatOut = FOut.X_tot - FOut.Xs; XwatOut(XwatOut < 0) = 0;
mVapOut = mDry .* FOut.X;
mWatOut = mDry .* XwatOut;
% Calculate the cumulative heating or cooling load
x = -(mDry .* (hDryIn - hDryOut) + ...
mVapIn .* hVapIn - mVapOut .* hVapOut + ...
mWatIn .* hWatIn - mWatOut .* hWatOut);
v = FOut.t;
if isvector(Q)
xq = Q;
else
xq = cumsum(Q);
end
for i=1:sz(2)
tOut(:,i) = interp1(x(:,i),v(:,i),xq(:,i));
end
tOut = [FIn.t ; tOut];
end
There is something strange, my collegue use the same codes, same version of MATLAB, but he got no problem,
but when I ran the script on my computer, it just gets errors
x is a 1000*50 double, v is a 1000*50 double, and xq is a 20*50 double, the data has no problem, I use x(:,1),v(:,1) and xq(:1) to do a interp1 function call, and there is no error. But when I ran my script, it show errors again
my test is here
K>>testx = x(:,1);
K>> testv = v(:,1);
K>> testxq = xq(:,1);
K>> interp1(testx,testv,testxq)
ans =
307.6069
307.0587
306.5055
305.9470
305.3835
304.8147
304.2408
303.6617
303.0773
302.4877
301.8929
301.2928
300.6874
300.0766
299.4607
298.8394
298.2129
297.5811
296.9440
296.3017
ran my script, the error is:
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 783)
tOut(:,i) = interp1(x(:,i),v(:,i),xq(:,i));
Error in at_fdplus.evap.plate_fin.PlateFinHE/calcBlock (line 250)
t.new.cf = CF.calcMoistHeatCool(mDot_CF,Q.wall,'Cooling',CF.p(1,:),CF.t(1,:),CF.X_tot(1,:));
Error in TestPlateFinHE (line 25)
Q.AKG = HE_AKG.calcBlock(FIN_HF,FIN_CF,mDot.hf,mDot.cf);

Sign in to comment.

 Accepted Answer

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

K>> locationOfNonfiniteX = find(~isfinite(x(:, i)))
locationOfNonfiniteV = find(~isfinite(v(:, i)))
locationOfNonfiniteXq = find(~isfinite(xq(:, i)))
locationOfNonfiniteX =
0×1 empty double column vector
locationOfNonfiniteV =
0×1 empty double column vector
locationOfNonfiniteXq =
0×1 empty double column vector
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.
the call of intterp1 function is indead a for-loop,but the value of x,v,xq are already defined, all value in these three arrays are 8 doubles, the first row of x is 0, x,v,xq are not calculated in a loop
part of data:
x = [0 0 0 0 ......
-33.4436754520186 -33.6320781597295 -33.8204638769074 -34.0088325974662 .....
-66.8773808240819 -67.2540736138778 -67.6307318006384 -68.0073553721683 .....
-100.301123027146 -100.865993391092 -101.430810918744 -101.995575591848 .....
-133.714908970212 -134.467844517515 -135.220708375837 -135.973500521303 ......
........
] x is 1000*50 double
v = [308.150000000000 308.150000000000 308.150000000000 308.150000000000 308.150000000000 ....
308.132735976222 308.132638705915 308.132541444217 308.132444191131 308.132346946660 ....
308.115471952443 308.115277411830 308.115082888434 308.114888382262 308.114693893320 ....
308.098207928665 308.097916117745 308.097624332651 308.097332573393 308.097040839980 .....
308.080943904887 308.080554823660 308.080165776868 308.079776764524 308.079387786640 .....
308.063679881109 308.063193529576 308.062707221086 308.062220955655 308.061734733300 .....
308.046415857330 308.045832235491 308.045248665303 308.044665146786 308.044081679960 .....
.....] v is 1000*50 double
xq = [-1047.32884340479 -1053.22978509923 -1059.13020454832 -1065.03010155478 ....
-2094.65768680958 -2106.45957019847 -2118.26040909665 -2130.06020310956 ....
-3141.98653021437 -3159.68935529770 -3177.39061364497 -3195.09030466434 ....
-4189.31537361916 -4212.91914039693 -4236.52081819330 -4260.12040621912 ....
-5236.64421702395 -5266.14892549617 -5295.65102274162 -5325.15050777390 ....
-6283.97306042875 -6319.37871059540 -6354.78122728994 -6390.18060932868 ...
-7331.30190383354 -7372.60849569464 -7413.91143183827 -7455.21071088346 ....
....] xq is 20*50 double
I find no infinite data in them

Sign in to comment.

More Answers (1)

I stilled don't know the reason of error, but the bug is fixed magically, I'm not sure what I did solved this problem, but thank you all guys for your valuable advice!

2 Comments

I‘m also getting the same error, but I don't know how to solve it.......
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

Sign in to comment.

Categories

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!