Simplifying the If statements.

1 回表示 (過去 30 日間)
Aftab Ahmed Khan
Aftab Ahmed Khan 2015 年 3 月 7 日
コメント済み: Aftab Ahmed Khan 2015 年 3 月 7 日
Hello Everyone, I am making this routing table for my network which is working fine but is there any efficient way of doing this, as i am running my simulation for 100000 iterations. In the following code, the variable idabs takes a value between 1 to 16 and depending on its value, the value of idcabs is generated accordingly.Thank you.
if any(idabs==[1:8])
cabs_vector=[9,10,11,12];
if idabs<=4
idcabs=cabs_vector((idabs))
else
idcabs=cabs_vector((idabs-4))
end
else
cabs_vector=[13,14,15,16];
if idabs<=12
idcabs=cabs_vector((idabs-8))
else
idcabs=cabs_vector((idabs-12))
end
end

採用された回答

James Tursa
James Tursa 2015 年 3 月 7 日
cabs_vector = [9 10 11 12 9 10 11 12 13 14 15 16 13 14 15 16];
idcabs = cabs_vector(idabs);
  1 件のコメント
Aftab Ahmed Khan
Aftab Ahmed Khan 2015 年 3 月 7 日
Ooh, Thank you. Seems like i should take a break now. Have a great weekend.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by