Effacer les filtres
Effacer les filtres

Why doesn't this simple search program work?

1 vue (au cours des 30 derniers jours)
Ayob
Ayob le 22 Jan 2014
Commenté : Ayob le 22 Jan 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?

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by