Implementing a routing table in Matlab
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, This is my routing table which i have made. I want to ask that is there any better way in which i can implement this. Thank you.
if any(idabs==[1,2,5,6])
hbsoption1=1; hbsoption2=5; hbsoption3=4; hbsoption4=6; hbsoption5=2; hbsoption6=3;
elseif any(idabs==([3,4,7,8]))
hbsoption1=2; hbsoption2=6; hbsoption3=3; hbsoption4=5; hbsoption5=1; hbsoption6=4;
elseif any(idabs==([9,10,13,14]))
hbsoption1=4; hbsoption2=8; hbsoption3=1; hbsoption4=7; hbsoption5=3; hbsoption6=2;
else
hbsoption1=3; hbsoption2=7; hbsoption3=2; hbsoption4=8; hbsoption5=4; hbsoption6=1;
end
댓글 수: 0
채택된 답변
Guillaume
2015년 3월 19일
One way:
ids = [1 2 5 6
3 4 7 8
9 10 13 14];
options = [1 5 4 6 2 3
2 6 3 5 1 4
4 8 1 7 3 2
3 7 2 8 4 1];
idabs = randi(20) %for demo
optionrow = find([any(idabs == ids, 2); 1], 1);
hbsoption = options(optionrow, :)
It's not a good idea to create numbered variables. A vector is a lot more useful.
추가 답변 (1개)
shivangi mahajan
2019년 11월 11일
if any(idabs==[1,2,5,6])
hbsoption1=1; hbsoption2=5; hbsoption3=4; hbsoption4=6; hbsoption5=2; hbsoption6=3;
elseif any(idabs==([3,4,7,8]))
hbsoption1=2; hbsoption2=6; hbsoption3=3; hbsoption4=5; hbsoption5=1; hbsoption6=4;
elseif any(idabs==([9,10,13,14]))
hbsoption1=4; hbsoption2=8; hbsoption3=1; hbsoption4=7; hbsoption5=3; hbsoption6=2;
else
hbsoption1=3; hbsoption2=7; hbsoption3=2; hbsoption4=8; hbsoption5=4; hbsoption6=1;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!