How to input functon arguments without order?

Is there a way for calling a function which has a lot of arguments without the order?
for example consider the following function:
function y=f(x1, x2, x3, x4, x5, x6)
%code
end
I would like to call it as follows:
f(x2=2, x1=4, x6=7, x4=0, x3=-1, x5=2.5)

 採用された回答

Steven Lord
Steven Lord 2022 年 8 月 17 日

0 投票

As of release R2021a you could do that by requiring all the inputs to be specified as name-value pair arguments. But if your function has many, many input arguments you might want to consider packing those inputs into a vector, a struct array, or an object.

2 件のコメント

danial19
danial19 2022 年 8 月 17 日
Would you give an example with non-2021 vesrsion?
Steven Lord
Steven Lord 2022 年 8 月 17 日
You can't, not as you've written it. What you've written is not syntactically legal in earlier releases.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

質問済み:

2022 年 8 月 17 日

コメント済み:

2022 年 8 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by