I have an expression that gives a matrix and I want to access an element, without creating a temporary variable, something like this cov(M)(1,1)
. How can I do it?
Thanks!
I have an expression that gives a matrix and I want to access an element, without creating a temporary variable, something like this cov(M)(1,1)
. How can I do it?
Thanks!
It's possible using anonymous functions:
>> f11 = @(M) M(1,1);
>> M = [1 2; 9 4];
>> cov(M)
ans =
32 8
8 2
>> f11(cov(M))
ans =
32
Or for the purists, here it is with no intermediate variables at all:
>> feval(@(M) M(1,1), cov(M))
ans =
32