Effacer les filtres
Effacer les filtres

How to use anonymous functions

3 vues (au cours des 30 derniers jours)
Ken
Ken le 5 Mar 2022
Commenté : Ken le 12 Mar 2022
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 commentaire
Walter Roberson
Walter Roberson le 5 Mar 2022
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?

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 5 Mar 2022
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 commentaires
Ken
Ken le 12 Mar 2022
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 le 12 Mar 2022
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Connectivity to ROS-Enabled Simulators dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by