How to index function-matrices?
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2017 年 11 月 23 日
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)
6 件のコメント
その他の回答 (1 件)
Andrei Bobrov
2017 年 11 月 23 日
function out = f(x,ii,jj)
a = [x,1;1,x];
out = a(ii,jj);
end
use
>> f(1,1,1)
ans =
1
>>
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!