Filter löschen
Filter löschen

Storing Function Handles in structure

9 Ansichten (letzte 30 Tage)
KieranSQ
KieranSQ am 11 Feb. 2020
Beantwortet: Stephen23 am 12 Feb. 2020
Hello,
I am trying to write a code such that I have a class of anonymous functions to which to call.
I would like to store them in some form of a dictionary, for example A.w1.pq = @(x,y,z) [x,y,z]. I would like to call these functions and extract the function and not neccessarily a numeric value. By this I mean if I call
a=A.w1.pq;
a(1) = @(x,y,z) x
Is there a way of doing this?
Any help would be appreciated.
  2 Kommentare
Adam Danz
Adam Danz am 11 Feb. 2020
This line below is extracting (or copying) the function.
a=A.w1.pq;
KieranSQ
KieranSQ am 12 Feb. 2020
I agree that this extracts the function vector. However, what I am ideally looking for is extracting the individual vector component as a function. I.e,
>> a=A.w1.pq;
%%%% Output
a(1) = @(x,y,z) x
a(2) = @(x,y,z) y
a(3) = @(x,y,z) z

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 12 Feb. 2020
>> fun = @(x,y,z) [x,y,z];
>> baz = @(n,v) v(n); % helper function
>> a = @(n) @(x,y,z)baz(n,fun(x,y,z));
Testing:
>> f = a(1); % f is a function handle!
>> f(5,6,7)
ans = 5
>> f = a(3); % f is a function handle!
>> f(5,6,7)
ans = 7

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by