Fixing Error "Subscript indices must either be real positive integers or logicals."
Show older comments
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!
Accepted Answer
More Answers (1)
Walter Roberson
on 17 Feb 2016
0 votes
You are indexing Io by a floating point value, but Io is a scalar. You probably wanted to multiply Io by the value.
1 Comment
Jordan Teich
on 17 Feb 2016
Categories
Find more on Bessel functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!