Subscript indices must either be real positive integers or logicals.???
조회 수: 1 (최근 30일)
이전 댓글 표시
Dear all,
I have defined the following function, where E is a 2-by-1 vector, Vn 2-by-2 matrix, c, u, sig_u_sn, sig_e_sn, gbar, all positive scalars. For example, I try the function with
[.149; .1448], [.02 0; 0 .009], .075, .15, .0004, .0004, 1
If I initialize E, Vn, c, u, sig_u_sn, sig_e_sn, gbar as above and run the code in the function, the code runs fine. BUT if I run the function using above, I get
"Subscript indices must either be real positive integers or logicals."
I googled around, but I'm really not sure why I get that message in my case. I'd really appreciate any and all helps. Thank you so much in advance!
Best, John
The function code below:
function y = y(E, Vn, M, c, u, sig_u_sn, sig_e_sn, gbar)
if c > 1.6*u*M^2
error('please try again');
end
xb = min(2*M*sqrt(2*max(u - gbar*sig_u_sn, 0)/c), 1);
y = zeros(1, 3);
if xb > 0
if sizecon(0, E, Vn, M, c, u, sig_u_sn, sig_e_sn, gbar) <= 0
y(1) = 0;
elseif sizecon(xb, E, Vn, M, c, u, sig_u_sn, sig_e_sn, gbar) <= 0
x0 = xb/2;
f = @(x) sizecon(x, E, Vn, M, c, u, sig_u_sn, sig_e_sn, gbar);
y(1) = fsolve(f, x0);
elseif xb < 1 && sizeunc(1, E, Vn, M, c, u, sig_u_sn, sig_e_sn) <= 0
x0 = (xb + 1)/2;
f = @(x) sizeunc(x, E, Vn, M, c, u, sig_u_sn, sig_e_sn);
y(1) = fsolve(f, x0);
else
y(1) = 1;
end
else
if sizeunc(0, E, Vn, M, c, u, sig_u_sn, sig_e_sn) <= 0
y(1) = 0;
elseif sizeunc(1, E, Vn, M, c, u, sig_u_sn, sig_e_sn) <= 0
x0 = 1/2;
f = @(x) sizeunc(x, E, Vn, M, c, u, sig_u_sn, sig_e_sn);
y(1) = fsolve(f, x0);
else
y(1) = 1;
end
end
y(3) = min((u - .125*c*(y(1)/M)^2)/sig_u_sn, gbar);
y(2) = E(1) - E(2)*y(1) + y(3)*(u - .125*c*(y(1)/M)^2) ...
- .5*(Vn(1, 1) + Vn(2, 2)*y(1)^2 - 2*Vn(1, 2)*y(1)) ...
- .5*(y(3)^2*sig_u_sn + sig_e_sn);
end
댓글 수: 2
dpb
2014년 7월 26일
Well, you could at least show the error message in context... :(
It means exactly what it says--somewhere you've got an array index that isn't integer-valued or a logical.
The likely candidates are sizecon() and perhaps sizeunc() look like arrays to Matlab instead of (I presume they're supposed to be) functions.
Image Analyst
2014년 7월 26일
You forgot to include the entire error message - ALL the red text -- you just snipped out a small portion of it for some reason. Failing that you could have attached your m-files, both the calling script and the function. So as it is, I've given up , unless you provide more info.
답변 (1개)
Azzi Abdelmalek
2014년 7월 27일
Your function is called y, when you call your function y:
y=y(...)
The variable y will shadow the function y, I recommend to to change the name of your function
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!