How to index function-matrices?
Show older comments
Take for example: f =@(x) [x,1;1,x]
If you evaluate the function f, you get a matrix in return. Is there any way, to index this matrix before evaluating it?
Like f(1,1) and so forth.
Indexing the matrix while evaluating doesn't work either: f(1)(1,1)
You still need to refer to the result: f1 = f(1); f1(1,1)
=1
Accepted Answer
More Answers (1)
Andrei Bobrov
on 23 Nov 2017
function out = f(x,ii,jj)
a = [x,1;1,x];
out = a(ii,jj);
end
use
>> f(1,1,1)
ans =
1
>>
1 Comment
TheOpenfield
on 23 Nov 2017
Edited: TheOpenfield
on 23 Nov 2017
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!