Last active
October 13, 2015 22:26
-
-
Save tiborsimon/c3d1140d87614961d283 to your computer and use it in GitHub Desktop.
Simple Input Parser code samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ret = my_function(varargin) | |
params.a = 42; | |
params.b = 'answer'; | |
params.c = 55.3; | |
params = simple_input_parser(params, varargin); | |
% further functionalities that uses the params struct | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssin('A f L fs phi', 2, 440, 0.8, 48e3, 45) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssin('AfLfsphi', 2, 440, 0.8, 48e3, 45) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ret = my_function(varargin) | |
params.a = 0; | |
params.b = 0; | |
params.c = 0; | |
[params, flags] = simple_input_parser(params, varargin); | |
if flags.b | |
disp('b parameter was passed'); | |
end | |
% further functionalities | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssin('f', 440, 'A', 2, 'phi', 45, 'fs', 48e3, 'L', 0.8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% use this function to generate a sine wave | |
ssin(440, 2, 45, 48e3, 0.8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Running SimpleInputParserTests | |
.......... | |
.......... | |
.......... | |
... | |
Done SimpleInputParserTests | |
__________ | |
result | |
_________________________________ | |
[1x33 matlab.unittest.TestResult] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [validflag, errormsg] = my_validator_for_the_parameter_c(value) | |
validflag = value > 1; | |
errormsg = 'Parameter c has to be greater than 1..'; | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ret = my_function(varargin) | |
params.a = 0; | |
params.b = 0; | |
params.c = 0; | |
function [validflag, errormsg] = my_validator_for_the_parameter_c(value) | |
validflag = value > 1; | |
errormsg = 'Parameter c has to be greater than 1..'; | |
end | |
validators.c = @validate_c; | |
params = simple_input_parser(params, varargin, validators); | |
% further functionalities | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment