What is the best way to check the inputs of a function?
4 ビュー (過去 30 日間)
古いコメントを表示
What is the best way to check the inputs of a function in Matlab?
So far I found two 'nice options':
What do you think it is the best way? (Also, I have already started using validateattributes and I was wondering if I should change).
Thank you!
4 件のコメント
Stephen23
2023 年 4 月 24 日
"I would say i do not care about backward compatibility, but i do generally care about the other points"
採用された回答
Adam Danz
2023 年 4 月 24 日
I'm sure there are varying opinions on this. Here are some bits that might help with your decision.
- function argument validation was introduced in R2019b. Will the users of your function all use a release on or after 19b?
- you may find that error messages created by functional argument validation are more intuitive or simpler to understand
- is readability and organization important to you? The functional argument validation is neatly tucked away at the top of the code whereas validateattributes could be sprinkled throughout.
- does functional argument validation or validateattributes have the validation options you need?
As a MATLAB user in grad school, when the new function argument validation feature was released, it took me a while to convert from using validateattributes, primarily because most of the analysis software I wrote needed to function on machines that did not have MATLAB R2019b or later but also because I already was comfortable with validateattributes/validatestring/etc. When I switched over to using the new argument validation feature, I soon felt like it delivered a more consistent experience for the developer and for the user.
3 件のコメント
Adam Danz
2023 年 4 月 24 日
I haven't compared performance between validation techniques but I've wondered about this, too.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Argument Definitions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!