Help to fix error in interpolation in a structure
显示 更早的评论
Hi,
I wrote the following code. r134aPropertyTables.mat is a build in structure in matlab and I want to interpolate knowing the pressure and temperature. I am receiving the following error :
>> Entalpy(1,324.89)
Error using griddedInterpolant
Grid arrays must have NDGRID structure.
Error in interp2>makegriddedinterp (line 226)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 134)
F = makegriddedinterp(X, Y, V, method,extrap);
function [h] = Entalpy(P,T)
load('r134aPropertyTables.mat','r134aPropertyTables');
u = interp2( r134aPropertyTables.p, r134aPropertyTables.vapor.T, r134aPropertyTables.vapor.u, P, T);
v = interp2( r134aPropertyTables.p, r134aPropertyTables.vapor.T, r134aPropertyTables.vapor.v, P, T);
h = u + P*1e3*v;
end
2 个评论
Voss
2022-4-25
Can you upload r134aPropertyTables.mat (using the paperclip button)?
Abdel karim Nakhwe
2022-4-26
回答(1 个)
You might try using scatteredInterpolant instead of interp2. And I suspect "r134aPropertyTables.p" in your calls to interp2 should really be "r134aPropertyTables.vapor.Pr".
S = load('r134aPropertyTables.mat')%,'r134aPropertyTables');
S.ans
r134aPropertyTables = S.ans.r134aPropertyTables
% I just make up a couple of P and T values to interpolate to
P = [0.002 0.0025];
T = [200 250];
r134aPropertyTables.p % not the same size as vapor.T -> can't use these two together
r134aPropertyTables.vapor.T % T has no repetition, so it's not appropriate for a griddedInterpolant -> use a scatteredInterpolant
r134aPropertyTables.vapor % maybe use .vapor.Pr instead of .p (?)
uI = scatteredInterpolant( ...
r134aPropertyTables.vapor.Pr(:), ...
r134aPropertyTables.vapor.T(:), ...
r134aPropertyTables.vapor.u(:));
vI = scatteredInterpolant( ...
r134aPropertyTables.vapor.Pr(:), ...
r134aPropertyTables.vapor.T(:), ...
r134aPropertyTables.vapor.v(:));
u = uI(P,T)
v = vI(P,T)
h = u + P.*1e3.*v;
类别
在 帮助中心 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!