nested for loops conditions

3 views (last 30 days)
O Nawwar
O Nawwar on 21 Mar 2018
Answered: ttopal on 21 Mar 2018
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??

Answers (1)

ttopal
ttopal on 21 Mar 2018
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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!