1

Suppose I have defined f and t as such

f = @(x)(x.^2);
t = [4,5,6];

Then I know that f(t) = [16, 25, 36] and I would expect to be able to write something like

f(t)(1)

to get 16 right away. As I noted, I can't. Is there a way to chain indexing right after a function call? Perhaps writing the indexing as a MATLAB function? i.e. if l(4) were just syntactic sugar for, say, index(l, 4) I would write index(f(t), 1). Of course I can define such a function, but I am interested in knowing my options if I were to stick with already defined MATLAB functions and/or behavior.

RGS
  • 964
  • 2
  • 10
  • 27
  • MATLAB does not really natively support this but you can do it by overloading `subsref`. See this post for more information: http://stackoverflow.com/questions/3627107/how-can-i-index-a-matlab-array-returned-by-a-function-without-first-assigning-it – sco1 May 17 '17 at 18:18

1 Answers1

0

I hoped Matlab would be nice to have this feature like Python, but for some reason, it does not. Octave supports this though.

Xiangrui Li
  • 2,386
  • 2
  • 13
  • 17