Why doesn't this simple search program work?

1 view (last 30 days)
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?

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!