Stuart’s MATLAB Videos

Watch and Learn

MATLAB Basics: Functions and subfunctions 7

Posted by Doug Hull,

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.
Other videos have been gathered here: https://blogs.mathworks.com/pick/category/video/ Other MATLAB Basics posts have been gathered here: https://blogs.mathworks.com/pick/category/matlab-basics/

7 CommentsOldest to Newest

JanKees replied on : 1 of 7
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
Justin replied on : 2 of 7
can you show me how to write another function the would ask the user the value for the input of the variable
Doug replied on : 3 of 7
Justin, You are going to want to use the INPUT command. >> a = input('Give me a number: ') Enjoy, Doug
Justin replied on : 4 of 7
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?
Doug replied on : 5 of 7
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
Lee R replied on : 6 of 7
is vi always defined as the column vecor in matlab? if you had written a row vector would you need to write vj? if you have a matrix how would you do this (say turn the 2,2 element of a matrix to zero?
Doug replied on : 7 of 7
VI is a simple name I use for "Valid Indices" It is just my own short hand for a binary of sorts, no assumption of size or shape. It is my default name in a way, sort of like i is the default looping index.