nested for loops conditions
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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??
0 Commenti
Risposte (1)
ttopal
il 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!