필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to create a function that do not require all the input paramenters

조회 수: 1 (최근 30일)
Ricardo Duarte
Ricardo Duarte 2020년 11월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
Dear all,
I'm quite new using matlab and I'm trying to create a function with +- 30 input parameters. Then, when I call the function, in some cases, I don't need to use all input parameters.
According to this I would like to know if its possible to create a function with 30 input parameters but when using it, just use a few according to the need of the user.
I don't want to put [] in the parameters that I'm not using. I was thinking of somethins like : Test = funct('a', a, 'c', c); However, I have one of the input parameter requires a matrix and when I'm introducing the matrix I get an error.
Thank you in advance,
Ricardo

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 11월 1일
The correct way to do this is to use an input parser object and define some inputs as optional: https://www.mathworks.com/help/matlab/ref/inputparser.html. The documentation example shows how it can be done.
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 11월 1일
This will be a complicated approach. I suggest you follow input parser approach as given in the link in my answer. It may be difficult to understand initially, but once it is working, it will be much more robust.
John D'Errico
John D'Errico 2020년 11월 1일
Ugh. I STRONGLY recommend you follow the advice given by Ameer.

이 질문은 마감되었습니다.

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by