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!