nested for loops conditions

3 visualizaciones (últimos 30 días)
O Nawwar
O Nawwar el 21 de Mzo. de 2018
Respondida: ttopal el 21 de Mzo. de 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??

Respuestas (1)

ttopal
ttopal el 21 de Mzo. de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by