Data is not valid NDGRID format. /Interpn
Show older comments
I am having great difficulty with a particular usage of interpn(), despite using it with no problems throughout an App Designer application. The code is very large, but I managed to replicate the problem in the ~ 100 line script below. Everything before line 72 is just setting up parameters, the problem is between lines 72 to 79.
The problem is the interpn() call on line 79. If I replace the definition of AdvanceRatio (line 72) with the commented text, I get an error on line 79 indicating 'AdvanceRatioRow' is not valid NDGRID format. The subfunction griddedInterpolant is what throws the error.
I am stumped. If you evaluate both definitions of AdvanceRatio on line 72, they are (74,1) arrays of type double, identical to the precision of doubles. But one kills line 79, and the other works as intended. Guess which I need?
Where's Waldo...
Table_Cp_table = [0.032 0.084 0.098 0.138 0.206 0.25;...
0.029 0.075 0.094 0.132 0.198 0.242;...
0.025 0.066 0.088 0.128 0.188 0.233;...
0.022 0.058 0.08 0.12 0.178 0.223;...
0.009 0.045 0.07 0.11 0.163 0.214;...
-0.057 0.01 0.05 0.099 0.15 0.204;...
-0.188 -0.074 0.02 0.078 0.13 0.19;...
-0.338 -0.188 -0.04 0.04 0.105 0.175;...
-0.522 -0.338 -0.134 -0.017 0.07 0.15;...
-0.705 -0.525 -0.272 -0.11 0.023 0.118;...
-0.915 -0.726 -0.468 -0.248 -0.074 0.072;...
-1.092 -0.942 -0.717 -0.468 -0.254 0.019;...
-1.22 -1.12 -0.933 -0.741 -0.51 -0.059];
Table_Cp_x = [15 20 25 30 35 40];
Table_Cp_y = [0:0.2:2.4];
S = 10.81;
b = 9.3;
Cd0 = .02;
Clmax = 1.7;
eff = .6;
weight = 750;
RatedPower = 180;
RatedRPM = 2700;
D = 74/12;
Vne = 320;
ClminD = 0.3;
Clmin = -1;
MaxAlpha = 16;
MinAlpha = 10;
Gmax = 6;
Gmin = -5;
polar.alpha = [MinAlpha:1:MaxAlpha];
Clrate = (Clmax-Clmin)/(MaxAlpha/MinAlpha);
polar.Cl = Clrate.*(polar.alpha-MinAlpha)-Clmin;
polar.Cd = Cd0+(polar.Cl-ClminD).^2./(pi()*eff*b^2/S);
manPress = 29.92;
rho = 1.225; %ft, deg C
Output.AkroHorRho = rho;
Vcas = [10:10:Vne];
Vcas = Vcas./3.6;
theta = [-90:5:90]';
lengthTheta = length(theta);
Output.Pspecific = [];
posNLimit = min(Gmax,Clmax*rho*Vcas(1)^2*S/(2*g0*weight));
negNLimit = max(Gmin,Clmin*rho*Vcas(1)^2*S/(2*g0*weight));
Nzpos = [0:0.1:posNLimit];
Nzneg = [0:-0.1:negNLimit];
Nz = [flip(Nzneg),Nzpos]';
lengthNz = length(Nz);
repTheta = repmat(theta,lengthNz,1);
Nz = repelem(Nz,lengthTheta,1);
Vx = Vcas(1)*cosd(repTheta);
Vy = Vcas(1)*sind(repTheta);
rpm = ones(length(repTheta),1);
VmagUS = Vmag.*3.28;
rho = rho.*.0023769/1.225;
maxManifold = rho./.0023769.*29.92;
manPress = min(maxManifold,manPress);
P = RatedPower.*manPress./29.92.*rpm./RatedRPM;
n = RatedRPM*ones(length(repTheta),1)./60;
AdvanceRatio = 0.032832832832833*ones(size(VmagUS));%(n.*D).\VmagUS;
Cp = P.*550./(rho.*n.^3*D.^5);
AdvanceRatioRow = interpn(Table_Cp_y,Table_Cp_x,Table_Cp_table,AdvanceRatio,Table_Cp_x,'*linear');
[indexMesh, Table_Cp_xMesh] = ndgrid([1:length(Cp)]',Table_Cp_x);
%Data is poorly scaled so...
%Jrow = Jrow.*10;
%Cp=Cp.*10;
bladeAngle = interpn(indexMesh,AdvanceRatioRow,Table_Cp_xMesh,[1:length(Cp)]',Cp,'*linear');
2 Comments
Brian Cooper
on 5 Apr 2018
Walter Roberson
on 5 Apr 2018
Everything is an array to MATLAB. Scalars (1 x 1 arrays), isscalar(), are special in some circumstances having to do with mixed sizes. Some mathematical operations only make sense on vectors, (1 x N or N x 1 arrays), isvector(). Some operations only make sense on matrices (2d arrays), ismatrix().
To emphasize: every N x M array is both a matrix and an array. There is no way of distinguishing "matrix" and "2d array".
Answers (1)
Brian Cooper
on 5 Apr 2018
1 Comment
Walter Roberson
on 6 Apr 2018
It often helps to subtract two values assumed to be identical for testing, just to double check whether they really are identical.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!