필터 지우기
필터 지우기

Using arguments with optional parameters and repeating parameters

조회 수: 22 (최근 30일)
Brandon
Brandon 2023년 7월 27일
댓글: Brandon 2023년 8월 15일
function argumentTest(opt,repeat1)
arguments (Input)
opt.test1
opt.test2
end
arguments(Input,Repeating)
repeat1
end
end
This code does not work in MATLAB 2023a. It gives me the error "Positional arguments must be defined before name-value arguments.", which is not a valid error. I would think this is possible since opt in this example would not require an actual placement, but could be thrown anywhere in the function arguments. I think it has to do with exactly that, however. The placement of the optional argument could be in the place of a repeating argument, thus there is no way for it to know it is going on internally.

채택된 답변

Pratyush
Pratyush 2023년 8월 4일
I understant you get a error "Positional arguments must be defined before name-value arguments." for your function. In MATLAB, the error "Positional arguments must be defined before name-value arguments" occurs when you try to define positional arguments (arguments without a name-value pair) after name-value arguments (arguments with a name-value pair). Try swapping the parameters to the function, replace your function signature with:
function argumentTest(repeat1, opt)
This should resolve the error.
  댓글 수: 1
Brandon
Brandon 2023년 8월 15일
Interesting. If I wanted all types of input arguments, then I have to split the input arguments into two parts.
function argumentTest(nonopt,repeat1,opt)
arguments (Input)
nonopt
end
arguments(Input,Repeating)
repeat1
end
arguments (Input)
opt.test1
opt.test2
end
end
Thank you for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by