Index exceeds matrix dimensions. I can't figure out what I'm doing wrong, please help.

조회 수: 2 (최근 30일)
here is my code:
if true
S=[];
n=2;
w=abs(10^6);
v=1:998;
u= -1:1;
for a = -2 : 0.04 : 2
for b = -2 : 0.04 : 2
vec=[0;0];
n= 3: 1000; %n=1 and n=2 both equal 0
v(n+1)= a*v(n) + b*v(n-1) + u(n);
c= a + 1i*b; %using i instead of j
while (v(n+1) < w)
u= 1-2*rand(1);
v=vec;
n=n+1;
end %end while loop
if v(n+1) < w
S= [S c];
else
S=0;
end %end if statement
end %end b= for loop
end %end a= for loop
T=plot(S, '*');
axis(T,'square')
end
I don't know what this is supposed to plot cause i keep getting an "Index exceeds matrix dimensions." error. My TA didn't explain squat about what needed to be done and I really don't understand any sort or programming(even though I try my best it just doesn't click in my brain). An explanation would also be appreciated if anyone can help me. Thanks a bunch.

답변 (1개)

Star Strider
Star Strider 2015년 2월 13일
We can’t figure out what you’re doing wrong either, because you haven’t told us what line is throwing the error, the size of the array you are indexing into, or the value of the index in the line that is throwing the error.
We’re very good at MATLAB, but we’ve proven over time to be absolutely hopeless mind-readers.
  댓글 수: 12
Savanna
Savanna 2015년 2월 13일
c is supposed to equal each increment of a so from -2 to 2 increasing by .04 plus each increment of b(which is the same thing), while b is being multiplied by j. I made 'S' a size of 1x10000
Star Strider
Star Strider 2015년 2월 13일
That doesn’t mean anything to me. To fit in ‘S’ as you’ve written your code (at least as I understand it), ‘c’ must be a scalar. It cannot be a vector.

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by