nested for loops conditions

3 次查看(过去 30 天)
O Nawwar
O Nawwar 2018-3-21
回答: ttopal 2018-3-21
Hello, I am trying to create a periodic mesh in x and y. So I loop the rows using i and loop columns using j. I want to omit rows -3, -2, 0, and 8. I want to omit the column number 3. I am using the following lines:
for (i=-n_row/2:n_row/2)
for (j=-n_col/2:n_col/2)
if ((i!=-3) and (i!=-2) and (i!=0) and (i!=8) )
do my function;
end
end
end
These statements omit the rows efficiently. But I do not know how to omit the column. Any help??

回答(1 个)

ttopal
ttopal 2018-3-21
You are actually not using matlab syntax. And if you are comparing a value to list of values ( like i and -3,-2,0,8) you might want to use a function for that.
for i=-n:n
for j=-m:m
if (~ismember(i,[-3,-2,0,8]) && j~=0)
do my function
end
end
end

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by