Matlab function optional input arguments

Matlab function optional input arguments

Posted: naf On: 05.07.2017

I need to implement a function that does some image processing on a specific number of images nFrames that are located in a folder folder1. The function would look something like:. Let's say I have several folders with different numbers of images in each one.

What I need to have is optional input arguments, meaning that if the user wants, he can do the image processing for the first 10 images, for example, but if he does not specify the number, the function should perform the task on all the images.

And the same for the folders, there should be a default folder in case the user does not specify from which folder he wants to take the images. It also could be interesting that the user could call the function with 0, 1 or 2 input arguments.

But if I call the function with no input arguments it gives an error saying there's not enough input arguments. Is it possible to create a function that can have all of its arguments optional and moreover allow you to input 0, 1 or 2 according to your needs, taking into account that one is a number and the other one a string?

You can pass a variable containing a string, but then it would check if that string exists:. By posting your answer, you agree to the privacy policy and terms of service. Stack Overflow Questions Developer Jobs Documentation beta Tags Users. Sign up or log in to customize your list. Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads matlab function optional input arguments us.

Log In Sign Up.

Join the Stack Overflow Community. Stack Overflow is a community of 7. Join them; it only takes a minute: Optional input arguments on Matlab function Ask Question.

matlab function optional input arguments

The function would look something like: I have thought of using the exist function like forex experts for metatrader 4 Marta Sampietro 8. To fix the problem in your code: You can pass a variable containing a string, but then it would check if that string exists: Results ; end Possible ways to call the function: That works just fine, but I have one minor question.

That is not supported and I think what you ask for is wrong.

Nice Way to Set Function Defaults » Loren on the Art of MATLAB

You want the default to be all files, not a certain number of files. Let a be your default directory with 5 files and b another directory with 10 files. You probably want to process 10 frames in this case. I think I didn't explain so well.

For example, let's say you call the function like in the third case in your answer. The user gives the folder path, but not the number of frames he wants to process, so the nFrames variable should adopt the value of the total number of images inside the folder the user inputs. I have updated my code how I would implement it. Sign up or log in StackExchange.

How to code in Matlab: If an argument is empty, then default to "x" value? - Computational Science Stack Exchange

Sign up using Facebook. Sign up using Email and Password.

Optional Arguments Using Empty as Placeholder » Loren on the Art of MATLAB

Post as a guest Name. Stack Overflow works best with JavaScript enabled. MathOverflow Mathematics Cross Validated stats Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more 3.

matlab function optional input arguments

Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.

inserted by FC2 system