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:
function imgProc( nFrames,path )
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.
I have thought of using the exist function like this:
function imgProc( nFrames,path )
if exist( path,'var' ) == 0
path = 'img/record_space';
end
if exist( nFrames,'var' ) == 0
d = dir([ path,'\*.png' ]);
nFrames = length( d( not([ d.isdir ]) ) );
end
end
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?