File Exchange 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

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

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