Implementing a routing table in Matlab
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aftab Ahmed Khan
el 19 de Mzo. de 2015
Respondida: shivangi mahajan
el 11 de Nov. de 2019
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 comentarios
Respuesta aceptada
Guillaume
el 19 de Mzo. de 2015
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.
Más respuestas (1)
shivangi mahajan
el 11 de Nov. de 2019
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 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!