필터 지우기
필터 지우기

Subscript indices must either be real positive integers or logicals.

조회 수: 8 (최근 30일)
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));

채택된 답변

Image Analyst
Image Analyst 2013년 2월 15일
편집: Image Analyst 2013년 2월 15일
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?
  댓글 수: 3
Image Analyst
Image Analyst 2013년 2월 15일
편집: Image Analyst 2013년 2월 15일
So you have a 2D array where bD is independent, but R and theta indexes are matched (both 2, both 3, or both 4)? Then have the function look like this:
function F = ratio_rp_bf(R,theta,bD)
for r = 1 : length(R)
for b = 1 : length(bD)
F(b, r) = (16/3).*(1./bD(b)).*(1./R(r)).^3.*abs(sqrt((1./R(r)).^4-2.*(1./R(r)).^2.*cos(2.*theta(r))+1));
end
end
And call it like this in the main program:
F = ratio_rp_bf(R,theta,bD)
In the command window:
F =
106.5332 5.5303 1.2148 0.4980
10.6533 0.5530 0.1215 0.0498
1.0653 0.0553 0.0121 0.0050
0.1065 0.0055 0.0012 0.0005
Kelly
Kelly 2013년 2월 16일
I'm trying to compute F and plot a contour 2x2 subplot, bD is independent, R and theta are dependent, for each R there is a corresponding theta.
bD(1) R(1) theta(1)
bD(1) R(2) theta(2)
...
bD(2) R(1) theta(1)
bd(2) R(2) theta(2)
...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 2월 15일
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
Image Analyst
Image Analyst 2013년 2월 16일
Why not just specify xlim() and ylim()?
Kelly
Kelly 2013년 2월 16일
I tried and my contour won't show, so I thought if I just assigned the values it would work, but it doesn't.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by