Borrar filtros
Borrar filtros

Why doesn't this simple search program work?

1 visualización (últimos 30 días)
Ayob
Ayob el 22 de En. de 2014
Comentada: Ayob el 22 de En. de 2014
I wrote a program to give me some nodes as shown in the figure
For each node like i, I used 'Dim{i}=[something something]' in my programming which introduces the position of each node.
Each node has contact which some other nodes like what is shown for i=128
.
For each node like i, I introduce position as given below (from 1 to 13) :
.
For example:
NODZ{i}(1)=127
NODZ{i}(2)=144
...
NODZ{i}(13)=128
Differences between nodes is a constant value and is called D in my programming.
In part of my program, I used a kind of search program to give me neighborhood of each node like i for all p nodes:
for i=1:p
NODZ{i}=zeros(1,13);
for j=1:p
if Dim{j}==[Dim{i}(1)-D Dim{i}(2)]
NODZ{i}(1)=j;
end
if Dim{j}==[Dim{i}(1) Dim{i}(2)+D]
NODZ{i}(2)=j;
end
if Dim{j}==[Dim{i}(1)+D Dim{i}(2)]
NODZ{i}(3)=j;
end
if Dim{j}==[Dim{i}(1) Dim{i}(2)-D]
NODZ{i}(4)=j;
end
if Dim{j}==[Dim{i}(1)-D Dim{i}(2)+D]
NODZ{i}(5)=j;
end
if Dim{j}==[Dim{i}(1)+D Dim{i}(2)+D]
NODZ{i}(6)=j;
end
if Dim{j}==[Dim{i}(1)+D Dim{i}(2)-D]
NODZ{i}(7)=j;
end
if Dim{j}==[Dim{i}(1)-D Dim{i}(2)-D]
NODZ{i}(8)=j;
end
if Dim{j}==[Dim{i}(1)-2*D Dim{i}(2)]
NODZ{i}(9)=j;
end
if Dim{j}==[Dim{i}(1) Dim{i}(2)+2*D]
NODZ{i}(10)=j;
end
if Dim{j}==[Dim{i}(1)+2*D Dim{i}(2)]
NODZ{i}(11)=j;
end
if Dim{j}==[Dim{i}(1) Dim{i}(2)-2*D]
NODZ{i}(12)=j;
end
if Dim{j}==[Dim{i}(1) Dim{i}(2)]
NODZ{i}(13)=j;
end
end
end
BUT, when I run the program and ask it something like NODZ{128} it gives me:
>> NODZ{128}
ans =
127 0 129 113 0 0 114 112 126 160 130 0 128
This not correct because real value of NODZ{128} should be :
NODZ{128}=[127 160 129 113 143 145 114 112 126 160 130 99 128]
Why some members becomes zero, How can I solve it?

Respuesta aceptada

Amit
Amit el 22 de En. de 2014
A simple test is type
[Dim{128}(1) Dim{128}(2)+D]
and
Dim{144}
and see if they match.
  17 comentarios
Ayob
Ayob el 22 de En. de 2014
It's probably right.I will check it.
Ayob
Ayob el 22 de En. de 2014
IT WORKS., THANKS GOD., THANKS Amit.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time 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!

Translated by