How to index function-matrices?

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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Nov. de 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)

6 comentarios

TheOpenfield
TheOpenfield el 23 de Nov. de 2017
Okay, so in this case, you can not keep the function characteristics of said entry of the matrix.
I do not understand what you mean about keeping the function characteristics ?
If you need to define an anonymous function do this is, you can do that
g = @(x) x*INDEX2(f(x),1,1)
MINDEX = @(x, R, C) INDEX2(M(x), R, C)
TheOpenfield
TheOpenfield el 23 de Nov. de 2017
I see, works the same way as seen below. There is still another problem to solve:
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?
As I said,
MINDEX = @(x, R, C) INDEX2(M(x), R, C)
TheOpenfield
TheOpenfield el 23 de Nov. de 2017
Ahhh, I see! That's it!

Iniciar sesión para comentar.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 23 de Nov. de 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 comentario

TheOpenfield
TheOpenfield el 23 de Nov. de 2017
Editada: TheOpenfield el 23 de Nov. de 2017
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?

Iniciar sesión para comentar.

Categorías

Preguntada:

el 23 de Nov. de 2017

Comentada:

el 23 de Nov. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by