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 commentaires

Voss
Voss le 25 Avr 2022
Can you upload r134aPropertyTables.mat (using the paperclip button)?

Connectez-vous pour commenter.

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 = struct with fields:
ans: [1×1 struct]
S.ans
ans = struct with fields:
r134aPropertyTables: [1×1 struct]
r134aPropertyTables = S.ans.r134aPropertyTables
r134aPropertyTables = struct with fields:
p: [1.0000e-03 0.0011 0.0012 0.0013 0.0014 0.0015 0.0017 0.0018 0.0020 0.0022 0.0024 0.0026 0.0028 0.0031 0.0034 0.0037 0.0040 0.0044 0.0048 0.0052 0.0057 0.0062 0.0068 0.0074 0.0081 0.0088 0.0096 0.0105 0.0114 0.0125 0.0136 0.0148 0.0162 … ] liquid: [1×1 struct] vapor: [1×1 struct] u_min: 80 u_max: 510 p_min: 1.0000e-03 p_max: 5.5000 p_crit: 4.0593 u_crit: 381.7117 n_sub: 96 fluid: 'R134a'
% 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
ans = 1×100
0.0010 0.0011 0.0012 0.0013 0.0014 0.0015 0.0017 0.0018 0.0020 0.0022 0.0024 0.0026 0.0028 0.0031 0.0034 0.0037 0.0040 0.0044 0.0048 0.0052 0.0057 0.0062 0.0068 0.0074 0.0081 0.0088 0.0096 0.0105 0.0114 0.0125
r134aPropertyTables.vapor.T % T has no repetition, so it's not appropriate for a griddedInterpolant -> use a scatteredInterpolant
ans = 25×100
178.7814 179.6628 180.5547 181.4573 182.3707 183.2952 184.2310 185.1784 186.1375 187.1085 188.0919 189.0877 190.0963 191.1178 192.1527 193.2011 194.2634 195.3398 196.4307 197.5363 198.6570 199.7932 200.9451 202.1131 203.2976 204.4989 205.7174 206.9536 208.2078 209.4804 193.0563 193.8518 194.6572 195.4727 196.2985 197.1349 197.9820 198.8400 199.7092 200.5898 201.4820 202.3861 203.3023 204.2308 205.1720 206.1261 207.0934 208.0741 209.0685 210.0770 211.0999 212.1374 213.1900 214.2578 215.3414 216.4409 217.5569 218.6897 219.8396 221.0071 206.6391 207.3616 208.0934 208.8347 209.5857 210.3466 211.1176 211.8989 212.6907 213.4932 214.3067 215.1314 215.9675 216.8152 217.6748 218.5466 219.4309 220.3278 221.2377 222.1608 223.0975 224.0480 225.0128 225.9920 226.9860 227.9952 229.0199 230.0605 231.1173 232.1907 219.6159 220.2748 220.9424 221.6190 222.3046 222.9995 223.7038 224.4178 225.1417 225.8756 226.6197 227.3744 228.1397 228.9160 229.7034 230.5023 231.3128 232.1352 232.9699 233.8169 234.6768 235.5496 236.4357 237.3355 238.2492 239.1772 240.1198 241.0773 242.0502 243.0387 232.0657 232.6682 233.2789 233.8978 234.5253 235.1613 235.8063 236.4602 237.1233 237.7958 238.4779 239.1699 239.8718 240.5839 241.3065 242.0398 242.7840 243.5393 244.3060 245.0844 245.8748 246.6773 247.4923 248.3201 249.1609 250.0152 250.8831 251.7650 252.6613 253.5724 244.0544 244.6061 245.1654 245.7324 246.3073 246.8903 247.4815 248.0811 248.6892 249.3061 249.9320 250.5670 251.2113 251.8652 252.5288 253.2024 253.8861 254.5803 255.2851 256.0009 256.7277 257.4660 258.2159 258.9778 259.7518 260.5384 261.3378 262.1504 262.9763 263.8161 255.6360 256.1414 256.6538 257.1734 257.7004 258.2348 258.7769 259.3268 259.8847 260.4507 261.0250 261.6078 262.1993 262.7997 263.4091 264.0279 264.6561 265.2940 265.9418 266.5998 267.2681 267.9471 268.6369 269.3379 270.0503 270.7743 271.5103 272.2586 273.0194 273.7930 266.8549 267.3177 267.7870 268.2629 268.7457 269.2354 269.7322 270.2362 270.7476 271.2666 271.7933 272.3279 272.8705 273.4214 273.9807 274.5486 275.1253 275.7110 276.3059 276.9103 277.5243 278.1481 278.7821 279.4265 280.0814 280.7472 281.4242 282.1125 282.8125 283.5245 277.7480 278.1712 278.6005 279.0360 279.4777 279.9258 280.3805 280.8419 281.3101 281.7853 282.2677 282.7573 283.2544 283.7592 284.2717 284.7922 285.3208 285.8578 286.4033 286.9576 287.5208 288.0932 288.6749 289.2662 289.8674 290.4786 291.1002 291.7324 292.3754 293.0295 288.3462 288.7325 289.1245 289.5221 289.9254 290.3347 290.7501 291.1715 291.5993 292.0336 292.4744 292.9220 293.3764 293.8378 294.3065 294.7825 295.2661 295.7573 296.2564 296.7636 297.2791 297.8030 298.3356 298.8770 299.4276 299.9875 300.5569 301.1361 301.7254 302.3249
r134aPropertyTables.vapor % maybe use .vapor.Pr instead of .p (?)
ans = struct with fields:
unorm: [25×1 double] v: [25×100 double] s: [25×100 double] T: [25×100 double] nu: [25×100 double] k: [25×100 double] Pr: [25×100 double] u_sat: [325.6143 326.0665 326.5255 326.9915 327.4645 327.9448 328.4324 328.9276 329.4305 329.9413 330.4600 330.9870 331.5224 332.0663 332.6189 333.1805 333.7511 334.3311 334.9206 335.5198 336.1290 336.7482 337.3779 338.0181 338.6691 339.3311 … ] u: [25×100 double]
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)
u = 1×2
358.5352 413.8279
v = vI(P,T)
v = 1×2
490.0902 293.1406
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!

Translated by