Need help creating Easy function
조회 수: 1(최근 30일)
Matt Tearle 2014년 10월 27일
MATLAB Academy can help you learn the basics of MATLAB. Or the "Getting Started" section in the doc.
You'll need to learn how to write a basic function. For example, the classic "area of a circle" function looks like this in MATLAB:
function A = areaofcircle(r)
A = pi*r.*r;
(file saved as areaofcircle.m). You need to write a function that, like this one, takes a single input called n and returns a variable that holds the value of 1*2*3*...*n. There are various ways to do that. A simple one is to use a for-loop. A "better" way is to use a vector and the prod function.
There is a factorial function in MATLAB. You can check that your function behaves the same as it: