How to access parameters from an anonymous function from another function

I have the anonym function getPLocalTransition. It has x as one of its parameters.
I have another function dir; I try to call x from the function dir but get error:
Unrecognized function or variable 'x'.
getPLocalTransition = @(localCoordinate) ...
pTransition(localCoordinate(1) + 3, localCoordinate(2) + 3);
localCoordinate(1)=1;
localCoordinate(2)=1;
x=localCoordinate;
pTransition(x(1) + 3, x(2) + 3);
function dir = get_direction(x_t, u_t, x_tm1)
......
pTransition(x);
end

4 件のコメント

Torsten
Torsten 2022 年 3 月 14 日
編集済み: Torsten 2022 年 3 月 14 日
In function "get_direction" there is no variable with the name "x" (at least if it is not created in the ...... section).
Ken
Ken 2022 年 3 月 14 日
Thanks. So if I want to call it from get_direction I have to declare it there?
Torsten
Torsten 2022 年 3 月 14 日
Yes, or you use the concept of a nested function:
Stephen23
Stephen23 2022 年 3 月 14 日
"...if I want to call it from get_direction I have to declare it there?"
Either pass it as an input argument or turn it into a nested function.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

質問済み:

Ken
2022 年 3 月 14 日

コメント済み:

2022 年 3 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by