필터 지우기
필터 지우기

How to find values in a table

조회 수: 11 (최근 30일)
Poseidon
Poseidon 2023년 11월 4일
편집: Poseidon 2023년 11월 5일
Hi,
I have a question, lets say I have a table like this
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.

채택된 답변

Walter Roberson
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
Walter Roberson 2023년 11월 5일
F = scatteredInterpolant(T.pressure, T.entropy, T.enthalpy);
interpolated_enthalpies = F(query_pressures(:), query_entropys(:));
Poseidon
Poseidon 2023년 11월 5일
편집: Poseidon 2023년 11월 5일
Thank you! This worked. But I think I have to use the previous answer (the subset) because for some cases its giving a wrong answer (like finding the enthalpy using entropy for a pressure).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by