MATLAB: Subscript indices must either be real positive integers or logicals.

errorfunction

Can someone please explain this error. Here is my code and function.
bD = [0.1, 1.0, 10, 100];
R = (1:1.25:5);
c = R;
a = 1/2*bD;
b = abs(sqrt(c.^2-a.^2));
theta = abs(atan(b./a));
[F] = ratio_rp_bf(R,theta,bD);
function [F] = ratio_rp_bf(R,theta,bD)
F(bD,R) = (16/3).*(1./bD).*(1./R).^3.*abs(sqrt((1./R).^4-2.*(1./R).^2.*cos(2.*theta)+1));

Best Answer

R takes on fractional values and thus can't be an index into an array. You don't need to put indexes for F in your function. Just do:
F = (16/3).*(1./bD).*(1./R).^3.*abs(sqrt((1./R).^4-2.*(1./R).^2.*cos(2.*theta)+1));
and it will make F a 1 by 4 array automatically. It will take the first values from all 3 arrays (bD, R, and theta), and then the second values, and then the third values, and then the last values. Is that what you want?