syntax of handle: f = @(X)find(X);

조회 수: 4 (최근 30일)
Yuji Zhang
Yuji Zhang 2013년 4월 24일
Hi everyone~
I'm learning about use handle. The usual syntax is h = @FuncName
But I also saw an example of f = @(X)find(X)
from here:
Can anyone please explain what the difference is? Can we use f = @find instead?
Thank you~

채택된 답변

Wayne King
Wayne King 2013년 4월 24일
편집: Wayne King 2013년 4월 24일
Yes, you can use
f = @find
instead in this case. For example:
y = zeros(10,1);
y(3:end) = 3:10;
f(y)
The way the example defines it gives you more flexibility in using find() for example
f = @(x)find(x>5)
f(y)
  댓글 수: 1
Yuji Zhang
Yuji Zhang 2013년 4월 24일
I see. And i tested to find f = @ find(x>5) is illegal.
Thank you Wayne~

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

추가 답변 (1개)

Matt J
Matt J 2013년 4월 24일
You should eventually read about Anonymous Functions
Briefly, you could use f=@find. The advantage of anonymous functions is that they allow you to point to functions which are not pre-packaged and which have more intricate forms. They can also take snapshots of other MATLAB workspace variables and use them as fixed parameters. E.g.,
a=1; b=2;
f=@(X) find(b*X>=a);
>> f([0,1,2])
ans =
2 3
  댓글 수: 1
Yuji Zhang
Yuji Zhang 2013년 4월 24일
편집: Yuji Zhang 2013년 4월 24일
i see i see. yea i saw this example: sqr = @(x) x.^2;
oops i want to accept this answer too. it seems i can't accept two of them both.
it's an excellent answer. Thanks a lot Matt~

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by