function val = sum(a,b)
default('a',1); % uses a function from file exchange
default('b',20);
val = a+b
end
I want to pass only the second argument and use the default for first,a. Something like below,
val = sum(b=2)
How can I do this in MATLAB?

 채택된 답변

Hussein Ammar
Hussein Ammar 2020년 8월 29일

1 개 추천

One way of doing this is to pass an empty argument, e.g., mySum([], 2) or mySum(2, []). So, you can add the following conditions:
function myVal = mySum(a, b)
if isempty(a)
a = 1;
end
if isempty(b)
b = 20;
end
myVal = a+b;
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 8월 29일

답변:

2020년 8월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by