Array indices must be positive integers or logical values.

조회 수: 1 (최근 30일)
Tove Rudöfors
Tove Rudöfors 2019년 10월 9일
댓글: Tove Rudöfors 2019년 10월 9일
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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by