フィルターのクリア

Why doesn't this simple search program work?

1 回表示 (過去 30 日間)
Ayob
Ayob 2014 年 1 月 22 日
コメント済み: Ayob 2014 年 1 月 22 日
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?

採用された回答

Amit
Amit 2014 年 1 月 22 日
A simple test is type
[Dim{128}(1) Dim{128}(2)+D]
and
Dim{144}
and see if they match.
  17 件のコメント
Ayob
Ayob 2014 年 1 月 22 日
It's probably right.I will check it.
Ayob
Ayob 2014 年 1 月 22 日
IT WORKS., THANKS GOD., THANKS Amit.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by