Matlab /
PassingArgumentsPassing arguments allows you to call one function from within another function, without foreknowledge of how many arguments the user will supply. This is done by passing the array of inputs as For example: h = plotRows(x,y,varargin) %% Function to plot rows of a matrix %Call plot for the transpose of x and y %and give the rest to plot as properties for the lines h(i) = plot(x',y',varargin{:}) This will create a function which you can call as:
To get 10 lines, which will all have default formatting. Or as:
To create 10 lines of line width 2. You can supply however many properties like the line width, and they will all be passed to
to get the same thing, unless you prefer to not have to think which way matlab plots a matrix. And that's exactly where this shines: Making wrappers so you don't have to think. |