MATLAB: I am getting the following error message and would like to know how I can remedy the integral error. Thanks.

integralintegralparseargsopstruct

Error using integralParseArgs (line 11)
Expected a string scalar or character vector for the parameter name.
Error in integral (line 87)
opstruct = integralParseArgs(varargin{:});
Error in Ass_2_AcousticOceans (line 120)
EJP(iy,ix,im)=integral(@(n2)f,n2,-inf,inf);
clear all
close all
clc
c1=1500;
c2=1800;
row1=1000;
row2=1200;
f=150;
w=2*pi*f;
h=50;
r=500;
k1=w/c1;
k2=w/c2;
b12=row1/row2;
Q=1;
m=5;
z=20;
zprime=40;
alphac=acos(c1/c2);
%Smz1=sin(n1*z); %mode shape at fluid channel
%Smz2=sin(n1*h)exp(-i*n2m(z-h)); %mode shape at fluid basement
if z<h %set z greater and lesser
zl=z;
zg=zprime;
else
zl=zprime;
zg=z;
end
% U=sqrt(1-(m*pi)^2/(k1*he*sin(alphac))^2);
% S1=sin(m*pi*z/he); %propagating mode shape 0<z<h
% S2=sin(m*pi*z/he).*exp(-k1*(z-h)*sin(alphac)*U); %evanescent mode shape z>h
phi=zeros(h,r,m);
EJP=zeros(h,r,m);
Res=zeros(h,r,m);
for im=1:1:m
for ix=1:1:r
for iy=1:1:h
he=h*(1+1/(b12*k1*h*sin(alphac)));
n1=(im*pi)/he;
n2=i*k1*sin(alphac)*(1-(im^2*pi^2)/(h^2*he^2*sin(alphac)))^0.5;
p=-k1*(1-(im^2*pi^2)/(k1^2*he^2))^0.5;
D=n1*cos(n1*h)+i*b12*n2*sin(n1*h);
F1=(sin(n1*zl)/n1)*(n1*cos(n1*(h-zg))+i*b12*n2*sin(n1*(h-zg)))/D;
F2=(sin(n1*zl)*exp(-i*n2*(zg-h)))/D;
if h<=h
Res(iy,ix,im)=(n1*sin(n1*z)*sin(n1*zprime))/...
(p*(n1*h-sin(n1*h)*cos(n1*h)-b12^2*sin(n1*h)*tan(n1*h)))*exp(i*p*ix);
f=n2/(k2^2-n2^2)^0.5*F1*exp(-i*(k2^2-n2^2)^0.5*ix);
EJP(iy,ix,im)=integral(@(n2)f,n2,-inf,inf);
else
Res(iy,ix,im)=b12*(n1*sin(n1*h)*sin(n1*zprime)*exp(-i*n2(z-h)))/...
(p(n1*h-sin(n1*h)*cos(n1*h)-b12^2*sin(n1*h)*tan(n1*h)))*exp(i*p*ix);
f=n2/(k2^2-n2^2)^0.5*F2*exp(-i*(k2^2-n2^2)^0.5*ix);
EJP(iy,ix,im)=b12*integral(@(n2)f,n2,-inf,inf);
end
phi(iy,ix,im)=(Q/(2*pi*ix^0.5))*(2*pi*i*Res(iy,ix,im)+EJP(iy,ix,im));
end
end
end
phi=sum(phi,3);
pcolor(h,x,abs(psi));

Best Answer

EJP(iy,ix,im)=integral(@(n2)f,n2,-inf,inf);
asks to run integral with anonymous function @(n2)f . The anonymous function takes a single parameter n2 and ignores it and returns whatever f is, which is an error because you need to return something the same size as the input.
The second parameter is the lower bound, and is given as n2 . The n2 that would be referred to would be the one constructed at
n2=i*k1*sin(alphac)*(1-(im^2*pi^2)/(h^2*he^2*sin(alphac)))^0.5;
This would not be the same n2 as the n2 referred to inside @(n2)f where it is used as a parameter name shadowing the assigned-to n2.
The third parameter is the upper bound, and is given as -inf . An upper bound of -inf is unusual, but not prohibited. As -inf is going to be less than whatever n2 was calculated at, you would get the negative from what you would have calculated if you had used -inf as the lower bound and n2 as the upper bound.
The fourth parameter, when present, must be a keyword for a keyword parameter pair. Instead you give +inf.