Array indices must be positive integers or logical values.

1 次查看(过去 30 天)
E = 10;
R1 = 10e3;
R2 = 1e3;
R3 = 4.7e3;
R4 = 10e3;
R5 = 10e3;
RX = 1e3;
RY = 1e3;
J = [E/R5 ; - E/R5; 0 ];
RYs = logspace(-3, 10, 10000);
IXs = [];
for ry = RYs
G = [ -(1/R5+1/R4+1/RX) 1/R5 1/RX;
1/R5 -(1/R5+1/R2+1/ry+1/R1) 1/R1;
1/RX 1/R1 -(1/R1 + 1/R3 + 1/RX) ];
V = G\J;
IXs(end+1) = ( V(3) - V(1) ) / RX;
end;
PXs = IXs .* IXs * RX;
figure('Name','RYandIXs','NumberTitle','off'); semilogx(RYs, IXs);
figure('Name','RYandPXs','NumberTitle','off'); semilogx(RYs, PXs);
maxIXs= max(IXs),
minIXs =min(IXs),
maxPXs= max(PXs),
minPXs = min(PXs)
MaxPXsAt = RYs(find(PXs == max(PXs)))
So this is the code I have written. Everything works fine except for the two min- functions. When I run the code I get the message "Array indices must be positive integers or logical values.". I have searched the internet for answers but no solution seems to be the one for me. Anyone know what might be the problem? Thank you :)

采纳的回答

meghannmarie
meghannmarie 2019-10-9
I ran your code and it works for me. This leads me to believe you might have a variable in your workspace named min. Try this:
which min
If that tells you min is a variable, rename that variable to something else.
  3 个评论
meghannmarie
meghannmarie 2019-10-9
I have had this happed to me numerous times by naming variables min, mean, max. So I figured thats what was happening when you posted this. Now I name my variables mn, avg, and mx.
Tove Rudöfors
Tove Rudöfors 2019-10-9
That's a really good tip! I will definitely be doing that too from now on. Thank you

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by