Interpolating between calling specific elements of the table

16 vues (au cours des 30 derniers jours)
Kosta
Kosta le 7 Nov 2016
Commenté : Kosta le 10 Nov 2016
Hello,
I have created this table of thermodynamic properties, however, I would like to be able to obtain a linearly interpolated value whenever the property I insert on my function is in between two values as listed on the table. I have tried different things such as 'if' function, but i cannot even start getting the progam to run with those.
The way the function works is I insert a pressure value for example instead of P, and a desired column from which i would like to obtain the property: i.e. R134a(80,'temp').
Any help would be greatly appreciated. Thanks in advance!
Below is the function:
function out=R134a(P,a)
M=[60 -36.9 0.0007098 0.3112 3.8 209.1 3.9 223.9 227.8 0.0164 0.9481 0.9645; 80 -31.1 0.0007185 0.2376 11.2 212.5 11.2 220.2 231.5 0.0472 0.9100 0.9572];
T=array2table(M,'variablenames',{'pres', 'temp','v_f','v_g', 'u_f', 'u_g', 'h_f', 'h_fg', 'h_g', 's_f', 's_fg', 's_g'}); [I,J]=find(M==P); T(I,a)
end
  1 commentaire
Peter Perkins
Peter Perkins le 9 Nov 2016
Kosta, I think you're going to have to give a short example of exactly what you need to do.

Connectez-vous pour commenter.

Réponse acceptée

Ahmet Cecen
Ahmet Cecen le 10 Nov 2016
Had something like this already, here it is:
function out=R134a(P,a)
% Your Table
M=[60 -36.9 0.0007098 0.3112 3.8 209.1 3.9 223.9 227.8 0.0164 0.9481 0.9645; ...
80 -31.1 0.0007185 0.2376 11.2 212.5 11.2 220.2 231.5 0.0472 0.9100 0.9572];
T=array2table(M,'variablenames',{'pres', 'temp','v_f','v_g', 'u_f', 'u_g', 'h_f', 'h_fg', 'h_g', 's_f', 's_fg', 's_g'});
% Find the location of 2 nearest Pressure Values in the Table - This can accomodate
% larger tables.
lowerPind = max(find( M(:,1) <= P ));
higherPind = min(find( M(:,1) >= P ));
% Find the interpolated value
if higherPind ~= lowerPind
out = T{lowerPind,a} + (P-M(lowerPind,1))*(T{higherPind,a} - T{lowerPind,a}) /...
(M(higherPind,1) - M(lowerPind,1));
else
out = T{lowerPind,a};
end
end
  1 commentaire
Kosta
Kosta le 10 Nov 2016
Thanks! I actually managed to use the interp1 function, it seems quite useful.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by