nested for loops conditions
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!