Asked by Matthew
on 24 Sep 2011

I am working on a humidity calculator. Basically, I have all the equations needed to solve the problem, but my calculator requires a bit of supressing with % to select the right method.

For those not familiar with humidity percentage, phi, is a function of the mass of water in the air (omega), OR Dew point, OR Wet Bulb temperature.

I would like to have a function like: phi_finder(T,P,Dew Point OR Wet Bulb OR Omega)

where if Dew Point shows up in the function it executes equation 1 without me having to supress equation 2 and equation 3 manually.

I know this is a problem something I should be able to solve in the help file but I had no idea what to sarch for.

Answer by Fangjun Jiang
on 24 Sep 2011

So your function will have three input arguments, T, P and one of Dew Point, or Wet Bulb, or Omega.

There is probably no easy way to tell whether the third input argument is Dew Point, or Wet Bulb, or Omega based on the value or data type. So I think you need to have a forth argument to specify it, like,

function Out=phi_finder(T,P,DPWBO,TypeStr), where TypeStr could be 'DewPoint', 'WetBulb', or 'Omega'. You could use any other type of identification as long as it is provided in the help text. You could also have a logic to say that if the forth input argument is not provided, that means the TypeStr is 'DewpOINT'.

help nargin help varargin

Then inside the function, it's just a matter of checking the TypeStr and use different equation.

Fangjun Jiang
on 24 Sep 2011

Yes. Check the correct syntax of if-elseif-else-end.

Also, use strcmpi() to compare the string.

Opportunities for recent engineering grads.

## 0 Comments