Matrix as an output of a function

1. Jun 21, 2011

phynewb

Hi guys

I am new to matlab. I have a question in how to pick up matrix elements as a output of a function.

Code (Text):
function result=test(E)
result=[1,2,3;4,5,6]*E;
For each E, test(E) will generate a 2x3 matrix.
I wonder how to pick up the matrix element,say test(2)(1,3).
When I type test(2)(1,3), it shows
??? Error: ()-indexing must appear last in an index expression.
So how can I pick up the matrix element?
Thank you.

2. Jun 21, 2011

a-tom-ic

Code (Text):

x = test(1);
x(1,3)

3. Jun 21, 2011

phynewb

Thank you a-tom-ic.
So I need other space to save the matrix first.

4. Jun 21, 2011

phynewb

But here comes the other question.
I need to integrate test(E)(1,3): int(test(E)(1,3),E1,E2).
If I set x=test(E), then int(x,E1,E2) will be problematic as shown "Undefined function or variable 'E'.
Is any way to solve this problem? Thank you for help.

5. Jun 22, 2011

a-tom-ic

HI Phynewb,

i'm sorry i don't understand what your trying to do! Supply more information on your variables and the task. What is E? The int-Function is symbolic toolkit isn't it?
Code (Text):

syms E;
int(E)
int(E,1,2)

6. Jun 22, 2011

phynewb

Thanks a-tom-ic.

Say, f1(E),f2(E),f3(E) are three functions. Here E is real number and the outputs are nxn real matrices.
Define F(E)=f1(E)*f2(E)*f3(E). So E is also an number and output is a matrix.
The purpose is to calculate the integration of F(E)(a,b) over E from E0 to E1. Here F(E)(a,b) means the (a,b) matrix element of F(E) and it is a number:
int(F(E)(a,b),E0,E1).

As you said, I cannot pick up the (a,b) element by F(E)(a,b). I have to save it as other variable, say G. Let G=F(E) and then take G(a,b).
But once you save it as other variable, how can I do the integration? Because G has no E-dependence.
int(G(a,b),E0,E1) is problematic!
I wonder if anyway to solve the problem.
Hopefully I explain it clearly.