Matlab Too Many Input Arguments and How to set default values on that
up vote
1
down vote
favorite
There are 8 input arguments in my function unstable_L(T1,T2,z1,z2,z3,z0h,z0m,U)
.
I would like to create this function with 5 required inouts and 3 optional inputs in which the optional value will be my default values that I have set if the user do not fill in. How can I make it? Is there any mistake in my coding?
nargin = 8;
if nargin > 8
disp (" the function unstable_L_new has only maximum of 8 input paramaters")
else
% Fill in unset optional values.
switch nargin
case 5
if isempty(z0h)
z0h = 0.005;
elseif isempty(z0m)
z0m = 0.005;
elseif isempty(U)
U = 2.0;
end
case 6
if isempty(z0m)
z0m = 0.005;
elseif isempty(U)
U = 2.0;
end
case 7
if isempty(U)
U = 2.0;
end
end
end
matlab
add a comment |
up vote
1
down vote
favorite
There are 8 input arguments in my function unstable_L(T1,T2,z1,z2,z3,z0h,z0m,U)
.
I would like to create this function with 5 required inouts and 3 optional inputs in which the optional value will be my default values that I have set if the user do not fill in. How can I make it? Is there any mistake in my coding?
nargin = 8;
if nargin > 8
disp (" the function unstable_L_new has only maximum of 8 input paramaters")
else
% Fill in unset optional values.
switch nargin
case 5
if isempty(z0h)
z0h = 0.005;
elseif isempty(z0m)
z0m = 0.005;
elseif isempty(U)
U = 2.0;
end
case 6
if isempty(z0m)
z0m = 0.005;
elseif isempty(U)
U = 2.0;
end
case 7
if isempty(U)
U = 2.0;
end
end
end
matlab
It depends on which arguments are optional, are they always the same? Or does the function just require 5/8 to work?
– rinkert
Nov 11 at 9:41
the last three arguments are optional, but the function must have all 8 inputs to function. I would like to write the function in which in case the user does not have enough data for the last three arguments, then matlab will recognise the last three arguments and fill in the default values that I set. is it posiible to do that?
– Yeoh
Nov 11 at 10:04
See my answer below, that should do exactly that.
– rinkert
Nov 11 at 10:14
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
There are 8 input arguments in my function unstable_L(T1,T2,z1,z2,z3,z0h,z0m,U)
.
I would like to create this function with 5 required inouts and 3 optional inputs in which the optional value will be my default values that I have set if the user do not fill in. How can I make it? Is there any mistake in my coding?
nargin = 8;
if nargin > 8
disp (" the function unstable_L_new has only maximum of 8 input paramaters")
else
% Fill in unset optional values.
switch nargin
case 5
if isempty(z0h)
z0h = 0.005;
elseif isempty(z0m)
z0m = 0.005;
elseif isempty(U)
U = 2.0;
end
case 6
if isempty(z0m)
z0m = 0.005;
elseif isempty(U)
U = 2.0;
end
case 7
if isempty(U)
U = 2.0;
end
end
end
matlab
There are 8 input arguments in my function unstable_L(T1,T2,z1,z2,z3,z0h,z0m,U)
.
I would like to create this function with 5 required inouts and 3 optional inputs in which the optional value will be my default values that I have set if the user do not fill in. How can I make it? Is there any mistake in my coding?
nargin = 8;
if nargin > 8
disp (" the function unstable_L_new has only maximum of 8 input paramaters")
else
% Fill in unset optional values.
switch nargin
case 5
if isempty(z0h)
z0h = 0.005;
elseif isempty(z0m)
z0m = 0.005;
elseif isempty(U)
U = 2.0;
end
case 6
if isempty(z0m)
z0m = 0.005;
elseif isempty(U)
U = 2.0;
end
case 7
if isempty(U)
U = 2.0;
end
end
end
matlab
matlab
edited Nov 11 at 13:04
Foo
1
1
asked Nov 11 at 9:32
Yeoh
62
62
It depends on which arguments are optional, are they always the same? Or does the function just require 5/8 to work?
– rinkert
Nov 11 at 9:41
the last three arguments are optional, but the function must have all 8 inputs to function. I would like to write the function in which in case the user does not have enough data for the last three arguments, then matlab will recognise the last three arguments and fill in the default values that I set. is it posiible to do that?
– Yeoh
Nov 11 at 10:04
See my answer below, that should do exactly that.
– rinkert
Nov 11 at 10:14
add a comment |
It depends on which arguments are optional, are they always the same? Or does the function just require 5/8 to work?
– rinkert
Nov 11 at 9:41
the last three arguments are optional, but the function must have all 8 inputs to function. I would like to write the function in which in case the user does not have enough data for the last three arguments, then matlab will recognise the last three arguments and fill in the default values that I set. is it posiible to do that?
– Yeoh
Nov 11 at 10:04
See my answer below, that should do exactly that.
– rinkert
Nov 11 at 10:14
It depends on which arguments are optional, are they always the same? Or does the function just require 5/8 to work?
– rinkert
Nov 11 at 9:41
It depends on which arguments are optional, are they always the same? Or does the function just require 5/8 to work?
– rinkert
Nov 11 at 9:41
the last three arguments are optional, but the function must have all 8 inputs to function. I would like to write the function in which in case the user does not have enough data for the last three arguments, then matlab will recognise the last three arguments and fill in the default values that I set. is it posiible to do that?
– Yeoh
Nov 11 at 10:04
the last three arguments are optional, but the function must have all 8 inputs to function. I would like to write the function in which in case the user does not have enough data for the last three arguments, then matlab will recognise the last three arguments and fill in the default values that I set. is it posiible to do that?
– Yeoh
Nov 11 at 10:04
See my answer below, that should do exactly that.
– rinkert
Nov 11 at 10:14
See my answer below, that should do exactly that.
– rinkert
Nov 11 at 10:14
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The way I understand your problem is that your last three arguments z0h
, z0m
and U
are optional.
The way you can make this work is by checking if they exist
function unstable_L(T1,T2,z1,z2,z3,z0h,z0m,U)
if (~exist('z0h', 'var'))
z0h = 1;
end
if (~exist('z0m', 'var'))
z0m = 0.005;
end
if (~exist('U', 'var'))
U = 2.0;
end
% rest of function
it works~! woa! Thanks a lot for helping! I really appreciate it
– Yeoh
Nov 11 at 10:36
Glad I could help, however, for future use of SO take a brief look here: stackoverflow.com/help/someone-answers
– rinkert
Nov 11 at 10:55
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The way I understand your problem is that your last three arguments z0h
, z0m
and U
are optional.
The way you can make this work is by checking if they exist
function unstable_L(T1,T2,z1,z2,z3,z0h,z0m,U)
if (~exist('z0h', 'var'))
z0h = 1;
end
if (~exist('z0m', 'var'))
z0m = 0.005;
end
if (~exist('U', 'var'))
U = 2.0;
end
% rest of function
it works~! woa! Thanks a lot for helping! I really appreciate it
– Yeoh
Nov 11 at 10:36
Glad I could help, however, for future use of SO take a brief look here: stackoverflow.com/help/someone-answers
– rinkert
Nov 11 at 10:55
add a comment |
up vote
0
down vote
The way I understand your problem is that your last three arguments z0h
, z0m
and U
are optional.
The way you can make this work is by checking if they exist
function unstable_L(T1,T2,z1,z2,z3,z0h,z0m,U)
if (~exist('z0h', 'var'))
z0h = 1;
end
if (~exist('z0m', 'var'))
z0m = 0.005;
end
if (~exist('U', 'var'))
U = 2.0;
end
% rest of function
it works~! woa! Thanks a lot for helping! I really appreciate it
– Yeoh
Nov 11 at 10:36
Glad I could help, however, for future use of SO take a brief look here: stackoverflow.com/help/someone-answers
– rinkert
Nov 11 at 10:55
add a comment |
up vote
0
down vote
up vote
0
down vote
The way I understand your problem is that your last three arguments z0h
, z0m
and U
are optional.
The way you can make this work is by checking if they exist
function unstable_L(T1,T2,z1,z2,z3,z0h,z0m,U)
if (~exist('z0h', 'var'))
z0h = 1;
end
if (~exist('z0m', 'var'))
z0m = 0.005;
end
if (~exist('U', 'var'))
U = 2.0;
end
% rest of function
The way I understand your problem is that your last three arguments z0h
, z0m
and U
are optional.
The way you can make this work is by checking if they exist
function unstable_L(T1,T2,z1,z2,z3,z0h,z0m,U)
if (~exist('z0h', 'var'))
z0h = 1;
end
if (~exist('z0m', 'var'))
z0m = 0.005;
end
if (~exist('U', 'var'))
U = 2.0;
end
% rest of function
answered Nov 11 at 9:46
rinkert
1,227317
1,227317
it works~! woa! Thanks a lot for helping! I really appreciate it
– Yeoh
Nov 11 at 10:36
Glad I could help, however, for future use of SO take a brief look here: stackoverflow.com/help/someone-answers
– rinkert
Nov 11 at 10:55
add a comment |
it works~! woa! Thanks a lot for helping! I really appreciate it
– Yeoh
Nov 11 at 10:36
Glad I could help, however, for future use of SO take a brief look here: stackoverflow.com/help/someone-answers
– rinkert
Nov 11 at 10:55
it works~! woa! Thanks a lot for helping! I really appreciate it
– Yeoh
Nov 11 at 10:36
it works~! woa! Thanks a lot for helping! I really appreciate it
– Yeoh
Nov 11 at 10:36
Glad I could help, however, for future use of SO take a brief look here: stackoverflow.com/help/someone-answers
– rinkert
Nov 11 at 10:55
Glad I could help, however, for future use of SO take a brief look here: stackoverflow.com/help/someone-answers
– rinkert
Nov 11 at 10:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247425%2fmatlab-too-many-input-arguments-and-how-to-set-default-values-on-that%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It depends on which arguments are optional, are they always the same? Or does the function just require 5/8 to work?
– rinkert
Nov 11 at 9:41
the last three arguments are optional, but the function must have all 8 inputs to function. I would like to write the function in which in case the user does not have enough data for the last three arguments, then matlab will recognise the last three arguments and fill in the default values that I set. is it posiible to do that?
– Yeoh
Nov 11 at 10:04
See my answer below, that should do exactly that.
– rinkert
Nov 11 at 10:14