How to index function-matrices?

조회 수: 7 (최근 30일)
TheOpenfield
TheOpenfield 2017년 11월 23일
댓글: TheOpenfield 2017년 11월 23일
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

채택된 답변

Walter Roberson
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
Walter Roberson
Walter Roberson 2017년 11월 23일
As I said,
MINDEX = @(x, R, C) INDEX2(M(x), R, C)
TheOpenfield
TheOpenfield 2017년 11월 23일
Ahhh, I see! That's it!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
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
>>
  댓글 수: 1
TheOpenfield
TheOpenfield 2017년 11월 23일
편집: TheOpenfield 2017년 11월 23일
This might be it!
Now i can do further calulations, without loosing the function characteristics, like:
g = @(x) x*f(x,1,1)
There might be still another problem:
In my case, my function is set up as a multiplication of matrices containing functions as entries. Like:
M = @(x) f(x)*f2(x)...
The multiplication of the matrices f, f2 is done while evaluating M at any point.
Is there any easy way to index this function too even though M doesn't know about its matrix properties before evaluation?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by