how to pull a single value from excel and use in a calculation in matlab.

2 次查看(过去 30 天)
hi all! i hope you are all doing well. i am super new to the matlab answers forum so hopefully i can explain what i need help with well enough...
So i have to create a psychometric chart that can work in any pressure; given only a pressure and two other variables,( dry bulb temperature, wet bulb temperature, relative humidity, and specific humidity), i have to solve for the left over variable plus enthalpy and specfic volume. I have all the if statments pretty much nailed but now i just need help with how to pull certain values from an excel file. for example if the user inputs a temperature of 25 degrees Celcius then i would like to have matlab go to the excel file and find the Saturation pressure @ the 25 degrees C and then attatch that to a variable Pg and then use it in an equation. This is what i have so far.
p= input('please input your local atmospheric pressure in kilo Pascal units: /n');
inp1 = input('Please select one of the following as your starting variable: Twb, Tdb, W, phi\n','s');
fprintf('Please enter the vaule for %s\n',inp1);
inp2 = input('');
inp3 = input('Please select one of the following as your second variable: Twb, Tdb, W, phi\n','s');
fprintf('please enter the value for %s\n',inp3);
inp4 = input ('');
if inp1 == 'Tdb' & inp3 == 'Twb'
hg=2500.9 + 1.82*inp2;
pg= % here is where i need to get MATLAB to go pull the sat. pressure from the excel file and if the value is not present then i would need
%matlab to use values above and below to interpolate one. then proceed to use the interpolated value.
pv=P-phi*pg
% in the other case i would use one of the selected variables to pull the other values from the table.
elseif inp1 == 'Tdb' & inp3 == 'W'
fprintf('it works1')
elseif inp1 == 'Tdb' & inp3 == 'phi'
fprintf('it works2')
elseif inp1 == 'Twb' & inp3 == 'W'
fprintf('it works3')
elseif inp1 == 'Twb' & inp3 == 'phi'
fprintf('it works4')
else inp1== 'W'& inp3 == 'phi'
fprintf('it works5')
end

回答(1 个)

Walter Roberson
Walter Roberson 2019-11-15
Unless you can be certain that the user can only choose values that are present to within round-off error (e.g., that they will not ask for 24.3 degrees when only 24 and 24.5 are present), then typically the easiest route is to read all of the data and use interp2() or similar.
In some cases you might be able to predict the row to read -- for example if you know you have 6 header entries and you know that the temperatures start at some value and increment by a certain value per row, then you could calculate back from temperature to excel row using 6 + 1 + round((user_temperature - first_temperature)/increment) . If you use floor() and ceil() instead of round() you could calculate the two rows that bracket the entry in the case the user entered something that does not exactly match.

Community Treasure Hunt

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

Start Hunting!

Translated by