Stuart’s MATLAB Videos

Watch and Learn

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the Original version of the page.

Managing code in MATLAB: Sub functions 3

Posted by Doug Hull,

This is the first series of MATLAB video tutorials that are an attempt to systematically make videos for a “technology trees” for using MATLAB. This first tree covers the various kinds of MATLAB files you might write. The tree shows you the order you should watch them because some rely on skills you need to learn from earlier videos, but some do not.

Script Function 1in1out MinNout VarArg Cell mode Markup Interactive Driver script Sub function Nested

This MATLAB tutorial video will show you how to make subfunctions in MATLAB. This allows you to have functions that are available only to other functions in the same file. This is ideal when you have subroutines that are only likely to be useful to the other functions in that file.

3 CommentsOldest to Newest

Tom Elmer replied on : 1 of 3
Yeah, the FOR loop was bugging me. I may need psychological help -- I think I have a problem :)
function approx = taylorSine(x)
  numTerms = 4;
  term = 1 : numTerms;
  n = term*2 - 1;
  correction = x.^n ./  factorial(n);
  oddsign = (-1).^(1+term);
  approx = sum(oddsign.*correction);
(Of course I just bypassed the whole point of the video... oops. I originally replaced it with an anonymous function isOdd = @(x) mod(x,2); Is there a support group called Functions Anonymous?) (testing, ignore this: isOdd = @(x) mod(x,2);, this concludes the test of the comment system.)
Dan replied on : 2 of 3
Hi, I'm a bit behind the times and have only just found this 'technology tree'. I really like it and found it very very helpful. Are there more in trees available? Thanks Dan
Doug replied on : 3 of 3
@Dan, Good to hear. I did not get a huge response, so it was the only one I built. I might build more in the future! Doug