Interpolating between calling specific elements of the table
2 次查看(过去 30 天)
显示 更早的评论
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
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!