Interpolating between calling specific elements of the table

2 ビュー (過去 30 日間)
Kosta
Kosta 2016 年 11 月 7 日
コメント済み: Kosta 2016 年 11 月 10 日
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 件のコメント
Peter Perkins
Peter Perkins 2016 年 11 月 9 日
Kosta, I think you're going to have to give a short example of exactly what you need to do.

サインインしてコメントする。

採用された回答

Ahmet Cecen
Ahmet Cecen 2016 年 11 月 10 日
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 件のコメント
Kosta
Kosta 2016 年 11 月 10 日
Thanks! I actually managed to use the interp1 function, it seems quite useful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by