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!