Reference excel spreadsheet column to retrieve data from corresponding row

13 views (last 30 days)
Hi, I am trying to find a way to pull corresponding values from an excel spreadsheet. I have 3 columns of data, in this order: Temperature, Enthalpy, Entropy.
Temperature ranges from 10-220 degrees with the corresponding enthalpy and entropy values in each row.
Is there a way to give MATLAB a value for temperature, and have it return the corresponding value for ONLY one of my two other columns? (i.e. - can I put in 20 for temperature and have it return the correct value for entropy?)
Is there a good help section/topic to explore to learn more about this coding/process?
Thank you in advance for your advice.

Answers (2)

Walter Roberson
Walter Roberson on 12 Oct 2013
interp1(temperature_column, enthalpy_column, temperature_to_probe_at)
  3 Comments
Walter Roberson
Walter Roberson on 12 Oct 2013
You can change the manner in which the interpolation is done by changing the options to interp1(). For example one of the options is "nearest"
If you want "last location that is at or before the probe location" then usually using histc() is better than using interp1()

Sign in to comment.


sixwwwwww
sixwwwwww on 12 Oct 2013
Dear J. Ryan Kersh, Walter Roberson's answer is correct. If you have confusion you can use the following code directly:
Temperature = xlsread(filename, 'A:A');
Enthalpy = xlsread(filename, 'B:B');
Entropy = xlsread(filename, 'C:C');
Search_at_temperature = input('Input temperature to find enthalpy and entropy at: ');
% Use to find Enthalpy for given temperature
Output_Enthalpy = interp1(Temperature, Enthalpy, Search_at_temperature);
disp(strcat('Enthalpy is: ', num2str(Output_Enthalpy)))
%Use to find Enthalpy for given temperature
Output_Entropy = interp1(Temperature, Entropy, Search_at_temperature); % Use to find Enthalpy for given temperature
disp(strcat('Entropy is: ', num2str(Output_Entropy)))
  1 Comment
sixwwwwww
sixwwwwww on 12 Oct 2013
I will like to add one comment here. In your excel sheet you have two temperature values same at 123.54 so please remove one of these two rows to use above code because otherwise function "interp1" doesn't work

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!