Help function inside the function

조회 수: 3 (최근 30일)
Ervin DeBoy
Ervin DeBoy 2020년 10월 21일
댓글: Stephen23 2020년 10월 21일
I want to type help function_name in the command window an the description should open
clear
function help = me(m)
help = 'generated numbers'
end

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 21일
편집: Ameer Hamza 2020년 10월 21일
The simplest way is to add comments right after the first line
function help = me(m)
% generated numbers
% write your code
end
Then you can type
help me
and it will displayes
generated numbers
For a more detailed documentation, refer to this link: https://in.mathworks.com/help/matlab/matlab_prog/display-custom-documentation.html
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 10월 21일
'x' is not used in your code, so you can define it like this
function [x1,x2] = dice() % <-- no 'x' needed here
%'This is a game of dice, you will receive 2 sets of outcomes, they are random generated numbers'
x1 = randi([1 6]);
x2 = randi([1 6]);
end
And call it like this
[x1, x2] = dice()
Ervin DeBoy
Ervin DeBoy 2020년 10월 21일
Thank you for helping :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number games에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by