"IdealAir interpolates from a table. It takes 3 arguments (a value, the variable to which the value is assigned, and the output variable)..."
Yes, it does.
"and assigns the output to a variable created within the script" ...
No, it does not. Don't worry, it is not your fault! The code certainly defines the variable, but this variable is not specified to be an output variable, so it never gets returned by the function!:
function IdealAir(xi,prop1,prop2,unit)
Whoever wrote that code (btw, it is a function and not a script) in their wisdom decided not to return any output arguments: it simply displays some values in the command window. This is rather bizarre, as expert code writers would consider that a function that generates useful values like this one does should simply return those values. The fact that the author named that final variable the same as the function name implies that the author has experience with VBA or some similar language, but sadly not with MATLAB (no h1 line is another big clue for that). It is easy to change that function to return an output argument, simply change the function definition line to this: function out = IdealAir(xi,prop1,prop2,unit)
and also these lines at the end of the file:
When we make those changes the function returns an output argument, exactly as you require for your code:
>> IdealAir(2.5,'so','h')
ans =
664.01
Best Answer