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!