필터 지우기
필터 지우기

How to write a function to find a value from a table.

조회 수: 1 (최근 30일)
me
me 2016년 7월 17일
댓글: Star Strider 2016년 7월 18일
I have a table that looks like this https://www.ohio.edu/mechanical/thermo/property_tables/air/air_Cp_Cv.html. I need to write a function with temperature as the input and the other three points of data as the output, but I am unsure of how to set up the code? How do I write a code that also interpolates if the temperature value is between two points of known data? I am very very new to matlab and am not at all sure how to even start. Any help would be greatly appreciated. Thank you in advance!
  댓글 수: 2
Image Analyst
Image Analyst 2016년 7월 17일
Is it a table, or a matrix of doubles? They're different and handled differently (look up table in the help if you don't understand why). Make it easy for us to help you by giving us code to generate the table variable, or matrix of doubles.
me
me 2016년 7월 18일
it is the exact table on that site. I guess you could make a matrix of them instead. It doesn't matter which way it is done... the simplest way would be fine. essentially i would like to create a function for which i would input a Temperature and get the three specific heat values(Cp, Cv, and k). the code i have so far is not really relevant to the function...its where i plan to use the function to get those values. I am just not even sure how to do the function at all. As i said, I have very little experience with matlab.

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

채택된 답변

Star Strider
Star Strider 2016년 7월 17일
I would use the interp1 function.
You can easily make a function from it:
M = [ 250 1.003 0.716 1.401
300 1.005 0.718 1.400
350 1.008 0.721 1.398
400 1.013 0.726 1.395];
CpCvk = @(TK) interp1(M(:,1), M(:,2:4), TK, 'linear', 'extrap');
T325 = CpCvk(325)
T325 =
1.0065 0.7195 1.399
  댓글 수: 2
me
me 2016년 7월 18일
Thank you so much for this!
Star Strider
Star Strider 2016년 7월 18일
My pleasure!
I didn’t plot the table, so see if an interpolation method other than 'linear' (such has 'pchip') might be more appropriate.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by