Accessing the first index of an anonymous function

42 Views Asked by At

If I have an anonymous function in MATLAB, say

f = @(t) [t, t+5];

and I wanted to create a new anonymous function g that accesses the first index of f, so that, in this example,

g = @(t) t;

how can I do so?

I have tried doing something along the lines of

g = @(t) f(t)(1);

but the compiler says that this is "invalid array indexing", even though I thought that this would basically allow g to be g(t) = t

1

There are 1 best solutions below

0
ShonenMind On

I believe I have resolved this. One can do the following:

f = @(t) [t, t+5];

first = @(t) t(1);

next = @(t) first(f(t));