Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Doug’s Pick of the Week

December 21st, 2007

MATLAB Basics: Functions and subfunctions

This six and a half minute video shows a function being created in MATLAB, then it shows a subfunction being added. Functions are a way of adding to the MATLAB language. This video shows the creation of a simple function, and then adding a subfunction to that original function.

Video Content

Find the files here.
PodCast here

Other videos have been gathered here:
http://blogs.mathworks.com/pick/category/video/

Other MATLAB Basics posts have been gathered here:
http://blogs.mathworks.com/pick/category/matlab-basics/

5 Responses to “MATLAB Basics: Functions and subfunctions”

  1. JanKees replied on :

    Doug:

    Good tutorial, as always. One thing that every time confuses me are the varargin, nargin, varargout, nargout options in a function. I believe that many users of Matlab also have the same problem.

    Could you, in a future post (may be a video), talk about them? I would be very gratefull if this happens.

    Yours,

    JanKees

  2. Justin replied on :

    can you show me how to write another function the would ask the user the value for the input of the variable

  3. Doug replied on :

    Justin,

    You are going to want to use the INPUT command.
    >> a = input(’Give me a number: ‘)

    Enjoy,
    Doug

  4. Justin replied on :

    function [choose] = a()
    choose=input(’Solve ‘,’s’);

    switch choose
    case {’Is’}
    h()
    case ‘Ic’
    disp(’c')
    otherwise
    disp(’unknown’)
    end;

    displayed in the command window

    ans

    Is
    What if i dont want Is to be displayed what should I do?

  5. Doug replied on :

    Justin,

    The display is coming from the results of the function a() being called.

    >>a();

    The semicolon will supress the print as you want.

    Doug

Leave a Reply


Doug Hull is an Application Engineer at The MathWorks. A MATLAB user since 1994, he gets paid to live, eat, and breathe MATLAB! This blog is dedicated to promoting the File Exchange by highlighting files and original video content.



  • pierre: Hi sherryl and thank you for answering me, Actually, I already tried before to use this property because I...
  • Sherryl: In Response to Post #10 by Bryan - Hi Bryan, By default the analog input object will acquire one second...
  • Sherryl: Hello Pierre, Please look at the OutOfDataMode property. http://www.mathworks .com/access/helpd...
  • Scott Hirsch: Elya - In v7.0, try aviread. This has straightforward syntax for reading a single frame - you could...
  • Scott Hirsch: Eric - That’s a nice suggestion. I often get frustrated when debugging GUIDE guis and ending up...
  • pierre: Hi all, I have the Data Acquisition Toolbox, and I’m trying for 2 weeks to send a step voltage, and...
  • Eric S: It would be great to stop the debugger from coughing somewhere inside the more “internal̶ 1;...
  • Tareq: coef1 = rand(1,3)-0.5; coef2 = rand(1,3)-0.5; lex1=roots(polyder(c oef1)) lex2=roots(polyder(c oef2)) hold all...
  • Luca Balbi: While we’re at it… Checking for a number to be zero is tricky in itself. We’re better...
  • david: perhaps some error checking is in order. After all, it is possible that our randomly generated quadratic...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.

Related Topics