MATLAB: How to feed MATLAB’s integral2 a vector of parameters using nested functions

arrayfunctionintegralMATLABvector

I want to calculate a 2D-integral for a vector of parameters in MATLAB. I know that integral2 has no 'ArrayValued' option. I've looked at a very similar question: I want to calculate a 2D-integral for a vector of parameters in MATLAB. I know that integral2 has no 'ArrayValued' option. I've looked at a very similar question: https://stackoverflow.com/questions/31032086/how-can-i-feed-matlabs-integral2-a-vector-of-parameters-via-nested-functions but am worried that my problem might be caused due to having a an array (T) of 2 dimensions in the overall for loops:
for j= 0:1:max_time
for n= 1:N
if n < N && n > 1 % Intermediate Layers
fun1 = @(lambda,mu) [(2*h*c^2./(lambda).^(5)).*(1./(exp(h*c./(lambda.*k_b.*Tp))-1)).*exp(-(z(n).*4*pi.*niquartz(n)./lambda-tauprime(n))./mu) + ...
(2*h*c^2./(lambda).^(5)).*(1./(exp(h*c./(lambda.*k_b.*T(n,j+1)))-1)).*(1-exp(-(z(n).*4*pi.*niquartz(n)./lambda-tauprime(n))./mu))].*2*pi.*mu;
fun2 = @(lambda,mu) [(2*h*c^2./(lambda).^(5)).*(1./(exp(h*c./(lambda.*k_b.*T(n,j+1)))-1)).*exp(-(z(n).*4*pi.*niquartz(n)./lambda-tauprime(n))./mu) + ...
(2*h*c^2./(lambda).^(5)).*(1./(exp(h*c./(lambda.*k_b.*T(n,j+1)))-1)).*(1-exp(-(z(n).*4*pi.*niquartz(n)./lambda-tauprime(n))./mu))].*2*pi.*mu;
Fplus(n,j+1) = integral2(fun1,7e-6,50e-6,0,1); % Upward Flux
Fneg(n,j+1) = integral2(fun2,7e-6,50e-6,0,1); % Downward Flux
end
end
The error message is "Matrix dimensions must agree." But technically, there are no matrices involved, since none of the parameters is array-valued anymore. What argument do I need to pass on differently? Alternatively, can you suggest a different way of approaching this integral?

Best Answer

There is currently no way to do this using integral2. As a workaround you could run integral2 separately for each parameter value or use a nested call to integral with 'ArrayValued',true.