for i=1:n-1
for j=1:n-1
for r=1:332
if i + r > 333
data(i+r,:)=0;
*else if i-r = < 0
data(i-r,:)=0;*
else if j+r > 333
data(:,j+r)=0;
else if j-r = < 0
data(:,j-r)=0;
end
end
end
end
end
end
end
Please tell me how I can correct the error at i-r = < 0

 채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 4일

1 개 추천

Change the '= <' to '<=' (without the apostrophes.)

댓글 수: 9

Amit
Amit 2012년 2월 4일
i do the correction, but there is one more error, plz tell me how i can correct it
??? Subscript indices must either be real positive integers or logicals.
data(i-r,:)=0;
Walter Roberson
Walter Roberson 2012년 2월 4일
Your code has (after correction to <= )
else if i-r <= 0
data(i-r,:)=0;
But if i-r <= 0 as found by the "if" test, then i-r is 0 or negative, and you are then trying to use that 0 or negative value as a subscript of "data".
Perhaps you wanted to test if i-r > 0 ?
You have the same problem with all of your "if" tests: you check for something that would be out of range, and when you find it, you use the out-of-range value!
Amit
Amit 2012년 2월 4일
thanks, yet there is one problem doing this
else if i-r > 0
data(i-r,:);
??? Attempted to access data(0,1); index must be a positive
integer or logical.
Walter Roberson
Walter Roberson 2012년 2월 4일
That would happen if your test was
elseif i-r >= 0
but that cannot happen if your test is
elseif i-r > 0
Amit
Amit 2012년 2월 4일
??? Attempted to access data(0,1); index must be a positive
integer or logical.
Error in ==> file at 30
s=s+data(i+r,j)+data(i-r,j)
Walter Roberson
Walter Roberson 2012년 2월 4일
That involves code you have not posted above. I would need to see the updated code.
Amit
Amit 2012년 2월 4일
The whole code look like this
n=length(data(1,:));
for i=1:n-1
for j=1:n-1
for r=1:332
if i + r > 333
data(i+r,:)=0;
else if i-r > 0
data(i-r,:);
else if j+r > 333
data(:,j+r)=0;
else if j-r > 0
data(:,j-r);
end
end
end
end
s=s+data(i+r,j)+data(i-r,j)
end
end
end
Walter Roberson
Walter Roberson 2012년 2월 4일
Your line s=s+data(i+r,j)+data(i-r,j) is outside of any of your "if" tests, so it is going to always be executed. It will cause a problem if i-r is 0 or negative.
Amit
Amit 2012년 2월 4일
Thanks Walter

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

추가 답변 (1개)

Jan
Jan 2012년 2월 4일

0 개 추천

Do you really have a space between the = and the < ? If so, remove it.
Please add the error message. Otherwise we have to guess, what your problem might be.

댓글 수: 1

Amit
Amit 2012년 2월 4일
Error: File: file.m Line: 19 Column: 33
The expression to the left of the equals sign is not a
valid target for an assignment.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2012년 2월 3일

편집:

2013년 9월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by