How to find values in a table
11 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a question, lets say I have a table like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1529797/image.jpeg)
In matlab I want to find/call a value in column 3 corresponding to say 100 in first column. Not only that, but I also want to use values not in the table (say for 95 in the first column) using linear interpolation. I want to be able to do this using any of the columns. How can I achieve this in MATLAB? Please help.
0 个评论
采纳的回答
Walter Roberson
2023-11-4
%let your table be named T
column_with_key = 1;
column_to_examine = 3;
value_to_lookfor = 100;
value_to_extrapolate = 95;
mask = T.(column_with_key) == value_to_lookfor;
wanted_value1 = T.(column_to_examine)(mask)
wanted_value2 = interp1(T.(column_with_key), T.(column_to_examine), value_to_extrapolate)
In practice it is usually shorter than this, such as just
wanted_value = interp1(T.var1, T.var3, 95)
6 个评论
Walter Roberson
2023-11-5
F = scatteredInterpolant(T.pressure, T.entropy, T.enthalpy);
interpolated_enthalpies = F(query_pressures(:), query_entropys(:));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!