MATLAB Answers

Error in Integration of Cell Array

6 views (last 30 days)
I am trying to perform integration on a cell array using the following code:
r = 2;
phi_e = 1.3694;
for e =1:1:size(A_schnitt,1)
for y =1:1:size(A_schnitt{e,1},1)
for u =1:1:size(A_schnitt{e,1},2)
fun= @(thetha_P) ((1/(2*pi))*A_schnitt{e,1}{y,u}.*exp(-1i*r*thetha_P(y,u)));
A{e,y,u}= integral(fun,0,phi_e, 'ArrayValued',true)
I am attaching the files
A_schnitt a multipel cell array which contains (5x1 cells, then each cell contains 3x63 cells and each cell is than a 2x2 matrix) and thetha_P which is a 3x63 double array.
The error which I am getting is
Index in position 2 exceeds array bounds (must not exceed 1).
Error in integralCalc/iterateArrayValued (line 156)
Error in integralCalc/iterateArrayValued (line 156)
fxj = FUN(t(1)).*w(1);
Error in integralCalc/vadapt (line 130)
[q,errbnd] = iterateArrayValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Does anyone knows..?


Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Jul 2020
fun= @(thetha_P) ((1/(2*pi))*A_schnitt{e,1}{y,u}.*exp(-1i*r*thetha_P(y,u)));
A{e,y,u}= integral(fun,0,phi_e, 'ArrayValued',true)
integral() is going to call the given function. Normally it would pass in a vector of values, but because you indicated ArrayValued as true, integral() is going to pass in one value at a time.
Inside your anonymous function, that scalar value is going to be received as the variable thetha_P . As indicated, it will be a scalar. But you attempt to index it with thetha_P(y,u)
thetha_P which is a 3x63 double array.
Not inside that anonymous function it will not be. You said @(thetha_P) so inside the anonymous function thetha_P is what is passed in, not whatever value thetha_P might have in the workspace.
I have to ask what variable you are integrating with respect to? What value in fun is intended to range over 0 to phi_e with the integral being formed out of it?


hamzah khan
hamzah khan on 14 Jul 2020
Walter Roberson
I am integrating with respect to the variable thetha_P. It has to be limited by phi_e and zero.
Here is the picture, which I am trying to do
here a(phi) is the matrix which is 2x2 and phi on the exponential is thetha_P. so I am trying to integrate a matrix
Walter Roberson
Walter Roberson on 14 Jul 2020
What is the role of your thetha_P matrix in this? Why are you indexing it in your code?
hamzah khan
hamzah khan on 15 Jul 2020
I got it actually, I had to use another variable for integration apart from thetha_P, then it works

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!