How to set a default value for my custom function
古いコメントを表示
I hope to create such custom function
function addnum(mat,n=numel(mat))
mat+n
I mean I try to add a number into the element of mtrix mat,but if I don't give a explicit value for n,I hope the n will be the number of the mtrix self.
採用された回答
その他の回答 (2 件)
KSSV
2017 年 7 月 17 日
function addnum(mat)
n=numel(mat)
mat+n
Lee
2023 年 2 月 11 日
This is the way to define default number in matlab
function addnum(mat,n)
arguments
mat
n=numel(mat)
end
mat+n
end
Be sure to list all arguments in order
カテゴリ
ヘルプ センター および File Exchange で 循环及条件语句 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!