I need an example of a defined function in M-files

Help me on how to define functions

댓글 수: 2

Jan
Jan 2012년 10월 4일
Such questions are explained exhaustively in the "Getting Started" chapters of the documentation. Reading this is obligatory, when you want to use such a powerful tool as Matlab.
I will try your suggestion

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

답변 (2개)

Walter Roberson
Walter Roberson 2012년 10월 4일

2 개 추천

Put the following into a file named example.m :
function example
disp('You rang?')
end
Then, invoke it by typing
example
at the command prompt.
It is important that the file name be a .m file that has the same name as the first "function" being defined in the file.
Matt Fig
Matt Fig 2012년 10월 4일

1 개 추천

  1. From the command line, type this: edit
  2. Copy the code below.
  3. Paste it into the blank window that opened from step 1.
  4. Save the file, use the name MATLAB gives it.
  5. From the command line, type this: mysquare(2)
function y = mysquare(x)
% mysquare(x) squares the input argument.
y = x.^2;

카테고리

질문:

2012년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by