How to index function-matrices?
6 views (last 30 days)
Show older comments
TheOpenfield
on 23 Nov 2017
Commented: TheOpenfield
on 23 Nov 2017
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
0 Comments
Accepted Answer
Walter Roberson
on 23 Nov 2017
No, there is no way to index the matrix before evaluating it.
To index after evaluating it, define
INDEX2 = @(Matrix, R, C) Matrix(R,C);
Then
INDEX2(f(1), 1, 1)
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
>>
See Also
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!