for if matrix

1 次查看(过去 30 天)
Amit
Amit 2012-2-3
编辑: Andreas 2013-9-30
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
Change the '= <' to '<=' (without the apostrophes.)
  9 个评论
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
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.

请先登录,再进行评论。

类别

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