フィルターのクリア

Why the third else if condition.. where i==1 && j==m went unexecuted

2 ビュー (過去 30 日間)
ravi shukla
ravi shukla 2020 年 8 月 17 日
コメント済み: ravi shukla 2020 年 8 月 17 日
A=zeros(12,1);
n=3;
m=4;
for i=1:n
for j=1:m
if (i==1) && (j==1)
A(1,1)=1;
elseif (i==1) && (j>1 || j<m)
A(2,1)=2;
elseif (i==1) && (j==m)
A(3,1)=3;
end
end
end
A

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 8 月 17 日
You want the third condition to execute the i==1 and j==4. However, this also meets the conditions of the first elseif:
elseif (i==1) && (j>1 || j<m)
This is because you use "or" instead of "and". When j==4, it is >1. Because of the or, it doesn't matter that it is <m. Try this instead: elseif (i==1) && (j>1 && j<m)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by