How to use anonymous functions

조회 수: 2 (최근 30일)
Ken
Ken 2022년 3월 5일
댓글: Ken 2022년 3월 12일
I am trying to understand anonymous functions. What exactly does this do:
pTransition = [
0 0 0 0 0
0 .05 .1 .05 0
0 .1 .4 .1 0
0 .05 .1 .05 0
0 0 0 0 0 ];
getPLocalTransition = @(localCoordinate) ...
pTransition(localCoordinate(1) + 3, localCoordinate(2) + 3);
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 3월 5일
What exactly does this do
We do not know exactly what it does. The details of how function handles are created and processed internally are MATLAB proprietary details, hidden in code that people outside Mathworks do not have access to.
I could probably spend more than an hour writing up and providing references to how it probably works internally, in order to be consistent with actions we can test and documentation we have access to, but unless you are into Compiler Construction, and Denotation Semantics, that would likely be a waste of my time, compared to the possibility that you could instead ask a specific question that you are trying to resolve in your mind.
When you get into an elevator and you ask "How exactly does this work?" are you asking about multi-phase motor theory, or are you asking about the material science behind the precise choice of compounds used in the emergency brakes, or are you asking about how the emergency phone works, or are you asking about how capacitance sensing works for the push buttons?

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

채택된 답변

KSSV
KSSV 2022년 3월 5일
The function needs a localCoordinate as input and it should be a 1X2 array. The array can have values 0,1,2.
Depedning on the values given, to the array 3 is added, these are the indices and the respective values are extracted from pTransition.
  댓글 수: 74
Ken
Ken 2022년 3월 12일
Got a response:
"You now have 2 issues left, the first one is about the MATLAB function syntax: When you define a function with function dir = get_direction(x_t, u_t, x_tm1), the variable dir is what gets returned in the end, so your code has always returned [0,0] so far.
The second is about the vector that you are calculating. The matrix pTransition describes the probability to move onto a neighbouring cell of x_tm1+u_t, further getPLocalTransition(...) expects a direction vector that is relative to this location. Since you use u_t+x_tm1 as input, which is relative to wold origin (0,0), this will most likely result to a probability of 0 (because the map is much bigger than the 5x5 of pTransition)."
Ken
Ken 2022년 3월 12일
I tried this i.e. did not use dir=[0;0]. Then I used the foll sentence to convert to local coordinates. Still no luck. getPLocalTransition(pTransition(localCoordinate(1) + 3, localCoordinate(2) + 3)); function dir = get_direction(x_t, u_t, x_tm1); temp = u_t + x_tm1 ; dir = getPLocalTransition(max(-2,min(2,temp))); dir= getPLocalTransition(pTransition(localCoordinate(1) + 3, localCoordinate(2) + 3)); end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by