필터 지우기
필터 지우기

How can I use InputParser with multiple argument names?

조회 수: 1 (최근 30일)
Alejandro Arrizabalaga
Alejandro Arrizabalaga 2018년 1월 11일
편집: Fangjun Jiang 2018년 1월 11일
I would like to use InputParser with multiple possible argument syntax for the same argument. For instance, to have shorter versions, e.g. that I can do:
do_something('factor',2)
and
do_something('f',2)
with the same result. I tried to use InputParser with cell arrays or char arrays but that does not work. Does someone know how to do this?

채택된 답변

Steven Lord
Steven Lord 2018년 1월 11일
Set the PartialMatching property of your inputParser instance to true.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2018년 1월 11일
편집: Fangjun Jiang 2018년 1월 11일
Since "PartialMatching" is true by default, do_something('f',2) is same as do_something('factor',2) if you don't have another parameter name starting with 'f'. In that case, you don't need to do anything extra in terms of InputParser.
If you do have multiple parameter names starting with 'f', I would specify both 'factor' and 'f' as optional argument. Inside the function, you can have processing to treat the parameters the same. But I guess it will not work if the argument is required.

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by