User Tools

Site Tools


gibson:teaching:fall-2014:math445:lecture8-diary

**This is an old revision of the document!** ----

A PCRE internal error occured. This might be caused by a faulty plugin

====== Math 445 lecture diary: if-elseif-else ====== Today we'll look at slightly more complex functions, with * multiple arguments * multiple return values * ''if-elseif-else'' statements * ''switch'' statements The declaration of a function ''f'' with multiple arguments and multiple return values has general form <code matlab> function [rtn1, rtn2, rtn3, ...] = f(arg1, arg2, arg3, ...) </code> The general form of an ''if-elseif-else'' statement is <code> if condition1 action1 elseif condition2 action2 elseif condition3 action3 else action4 end </code> though of course you can have as many ''elseif'' statements as you like. ====Example: if-elseif-else and multiple args and return val==== Write a Matlab function ''temp2kcf'' converts a temperature ''t'' in any one of the three units Kelvin, Celsius, or Farenheit, and returns the temperature in all three units. The function should have two arguments, the temperature ''t'' and a character ''units'' which specifies the units as either K, C, or F and three return values, ''tK, tC, tF''.

gibson/teaching/fall-2014/math445/lecture8-diary.1412796552.txt.gz · Last modified: 2014/10/08 12:29 by gibson