MATLAB: Varargin

cell arraysfunction

How can I check the input argument of a function to see if a specific string has been input? For example, I want to see if the user has input 'filename' in the function argument then the function reads the file name in the argument as well and writes the data into it otherwise doesn't write anything to any file.
myfunc(x, y, z, 'filename', 'mydata.txt') —> writes to mydata.txt
myfunc(x, y, z) —> does not write to any file
Actually, I have 10 possible cases and I want to be able to check which of those cases is in the input argument and based on that take the appropriate action like plot function which you can specify 'color', linewidth', 'linetype', and other plot properties arbitrarily.
Thanks, Ahmad

Best Answer

doc inputParser
With 10 possibilities, I think an inputParser object is the way to go. With only 1 or two possibilities, the inputParser might also be teh way to go.