Difference between revisions of "MATLAB talk:Inline Function"

From PrattWiki
Jump to navigation Jump to search
 
 
Line 1: Line 1:
{{Q}}Can arguments put in to the inline function be functions themselves or do they have to be defined numbers?[[User:Yd31|Yd31]] 11:48, 25 January 2012 (EST)
+
* Can arguments put in to the inline function be functions themselves or do they have to be defined numbers?[[User:Yd31|Yd31]] 11:48, 25 January 2012 (EST)
 +
** The items in the ''first'' argument can include functions.  The second argument and beyond need to be variable names.  But you can certainly have something like <source lang="matlab">c = inline('sqrt(a.^2+b.^2)', 'a', 'b')</source>which uses the function <code>sqrt</code> as a part of the inline. Also, when calling the function, you can have functions that return values - for example:<source lang="matlab">MyVal = c(cos(pi/6), sin([1 2 3]*pi/6))</source>which would return the three values of the function for the single value of the first argument matched against the three values of the second.[[User:DukeEgr93|DukeEgr93]] 13:35, 25 January 2012 (EST)

Latest revision as of 18:35, 25 January 2012

  • Can arguments put in to the inline function be functions themselves or do they have to be defined numbers?Yd31 11:48, 25 January 2012 (EST)
    • The items in the first argument can include functions. The second argument and beyond need to be variable names. But you can certainly have something like
      c = inline('sqrt(a.^2+b.^2)', 'a', 'b')
      
      which uses the function sqrt as a part of the inline. Also, when calling the function, you can have functions that return values - for example:
      MyVal = c(cos(pi/6), sin([1 2 3]*pi/6))
      
      which would return the three values of the function for the single value of the first argument matched against the three values of the second.DukeEgr93 13:35, 25 January 2012 (EST)