Help to fix error in interpolation in a structure
Afficher commentaires plus anciens
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 commentaires
Voss
le 25 Avr 2022
Can you upload r134aPropertyTables.mat (using the paperclip button)?
Abdel karim Nakhwe
le 26 Avr 2022
Réponses (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;
Catégories
En savoir plus sur Interpolation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!