Subscript indices must either be real positive integers or logicals.
Show older comments
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));
Accepted Answer
More Answers (1)
Walter Roberson
on 15 Feb 2013
R includes numbers with fractions, but inside ratio_rp_bf, you are trying to assign to F(bD,R) which is an attempt to assign use R as a subscript.
If you are trying to define a function f(x,y) by using an assignment
f(x,y) = <something>
then the only time you can do that is if you are using R2012a or later and you have already defined the function as symbolic
syms f(x,y)
MATLAB does not use assignment to f(x,y) as the notation for creating functions.
My guess as to what you want to do would be
function F = ratio_rp_bf(R,theta,bD)
[Rmat, bDmat, thetamat] = ndgrid(R, bD, theta);
F = (16/3).*(1./bDmat).*(1./Rmat).^3.*abs(sqrt((1./Rmat).^4-2.*(1./Rmat).^2.*cos(2.*thetamat)+1));
end
Notice that this will return a 3D array, as your R, theta, and bD are all vectors.
Possibly you want to use R and theta linked together, always using R(K), theta(K) together? But that you want bD to be an independent axis?
10 Comments
Kelly
on 15 Feb 2013
Kelly
on 15 Feb 2013
Walter Roberson
on 15 Feb 2013
meshgrid() will transpose the outputs.
Are you trying to compute with
bD(1), R(1), theta(1)
bD(1), R(1), theta(2)
bD(1), R(1), theta(3)
...
bD(1), R(2), theta(1)
or are you trying to compute with
bD(1), R(1), theta(1)
bD(1), R(2), theta(2)
bD(1), R(3), theta(3)
...
bD(2), R(1), theta(1)
with the R index always the same as the theta index?
Kelly
on 16 Feb 2013
Image Analyst
on 16 Feb 2013
The code I gave you does that. The indexes for R and theta are in lockstep, just like you showed.
Kelly
on 16 Feb 2013
Image Analyst
on 16 Feb 2013
Then go ahead and mark as "Answered"
Kelly
on 16 Feb 2013
Image Analyst
on 16 Feb 2013
Why not just specify xlim() and ylim()?
Kelly
on 16 Feb 2013
Categories
Find more on Polar Plots 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!