The @ symbol in Matlab

조회 수: 696 (최근 30일)
Emma
Emma 2019년 10월 17일
댓글: Steven Lord 2024년 1월 23일
What does f = @(n) ((1/2).^n).*(n>=0); mean? Is this the (1/2)^n function, for values of n greater than zero? I am not sure how the @ symbol works in Matlab as I have not found an adequate explanation in the Matlab documentation.

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 10월 17일

추가 답변 (2개)

POOPESH
POOPESH 2024년 1월 23일
what does the meaning of g=@(x)(x^2*(1-2*x));
  댓글 수: 1
Steven Lord
Steven Lord 2024년 1월 23일
It is an anonymous function. The first paragraph of that page is "An anonymous function is a function that is not stored in a program file, but is associated with a variable whose data type is function_handle. Anonymous functions can accept multiple inputs and return one output. They can contain only a single executable statement."
They are often used for small and simple functions to avoid having to create a separate function file.
By the way, you may want to vectorize your function so you can call it with an array of values, not just one value at a time.

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

Community Treasure Hunt

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

Start Hunting!

Translated by