MATLAB: Fixing Error “Subscript indices must either be real positive integers or logicals.”

besselerrorsubscript indices

I'm fairly new to Matlab have been trying to plot a few functions on a single figure and am having trouble with this error that popped up. I'm confused because I feel like with the kind of code I am writing this error shouldn't be an issue. My variable definitions and functions are below.
lam1=380E-9; % Wavelength of light in meters, violet
lam2=450E-9; % Wavelength of light in meters, blue
lam3=500E-9; % Wavelength of light in meters, green
lam4=580E-9; % Wavelength of light in meters, yellow
lam5=750E-9; % Wavelength of light in meters, red
R=5E-3; % Distance from aperture to observation plane in meters
a=3E-6; % Radius of the aperture in meters
Io=1; % Define Initial intensity of light
N = R/(2*a);
q=linspace(-1E-3,1E-3,1000); % Define radial distance from optical axis in observation plane in meters
I1 = Io(((2.*besselj(1,q).*((pi.*q)/(lam1.*N))))/(((pi.*q)/lam1.*N))).^2;
I2 = Io(((2.*besselj(1,q).*((pi.*q)/(lam2.*N))))/(((pi.*q)/lam2.*N))).^2;
I3 = Io(((2.*besselj(1,q).*((pi.*q)/(lam3.*N))))/(((pi.*q)/lam3.*N))).^2;
I4 = Io(((2.*besselj(1,q).*((pi.*q)/(lam4.*N))))/(((pi.*q)/lam4.*N))).^2;
I5 = Io(((2.*besselj(1,q).*((pi.*q)/(lam5.*N))))/(((pi.*q)/lam5.*N))).^2;
The error seems to arise when examining the I1 function. If anyone has an idea as to what the issue might, it would be much appreciated!

Best Answer

I think you missed the multiplication operator *
I1 = Io*(((2.*besselj(1,q).*((pi.*q)/(lam1.*N))))/(((pi.*q)/lam1.*N))).^2;