How do you use interp1?
3 views (last 30 days)
Show older comments
Hello, I am having trouble using the MATLAB function interp1. I want to create a table like the one in the image. My code is provided below. T is a given table you can see in the image. The second image is the one I am getting with the code and I want it to output the one like the third image. I also want the output to be able to take a column array of temperatures and output the calculated values.
function [ T2 ] = interpthermo(T,newT)
Interp_Function=T{sum(T{:,1}<newT),2}+((T{1+sum(T{:,1}<newT),2}-(T{sum(T{:,1}<newT),2}))/(T{1+sum(T{:,1}<newT),1}-T{sum(T{:,1}<newT),1}))*(newT-T{sum(T{:,1}<newT),1});
Temperature=sort([T{:,1};newT]);
new_Column=interp1(Temperature,Interp_Function);
Internal_Energy=sort([T{:,2};new_Column]);
T2=table(Temperature,Internal_Energy);
end
T =
5×2 table
Temperature Internal_Energy
___________ _______________
80 2487.3
120 2544.7
160 2602.7
200 2661.4
240 2721
>> interpthermo(T,90)
ans =
6×2 table
Temperature Internal_Energy
___________ _______________
80 2487.3
90 2544.7
120 2602.7
160 2661.4
200 2721
240 NaN
>> interpthermo(T,90)
ans =
6×2 table
Temperature Internal_Energy
___________ _______________
80 2487.3
90 2501.7
120 2544.7
160 2602.4
200 2661.7
240 2721
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!