How do I get my input from my initial function to be read by my helper function ie (n,mu,sigma)?

I'm trying to figure out how I would get the output from my function 'getValidArgs' into my helper function 'processArgs'. I've tried nesting the function but when it tries to read the values in the second function it doesn't recognise a value for n,mu,or sigma. I will attach a copy of the question and my code.

 Accepted Answer

Dan - look closely at the assignment instructions. The function getValidArgs is a function that accepts a variable number of arguments and returns three validated scalar values. That means that the signature for this function would be something like
function [n, mu, sigma] = getValidArgs(varargin)
which is almost what you have with the exception that varargin is the sole input parameter.
As for the helper function, processArgs, its input is a cell array named args which contains the contents of the variable length argument list which has been supplied to getValidArgs. And so its signature would be
function [n, mu, sigma] = processArgs(args)
where the input is args and not the name of the first function (like you have shown). The trick (or the assignment!) is to get you to call the second function from the first where you pass the inputs from the first function in to the second. See varargin for details on a variable-length input argument list.
As the helper function is processing the inputs to the primary function, then it should be clear on what gets passed to the helper.

More Answers (0)

Categories

Asked:

on 23 May 2015

Answered:

on 23 May 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!