Info

此问题已关闭。 请重新打开它进行编辑或回答。

"index exceeds matrix dimension" error

1 次查看(过去 30 天)
Kelil Mohammed
Kelil Mohammed 2018-5-8
关闭: MATLAB Answer Bot 2021-8-20
I want to calculate perimeter of a triangle formed by three anchor node a,b and c, in wireless sensor network. following is my code, any one help please how this error can be solved
function perim = perimeter(AB,AC,BC)
perim = AB+AC+BC; % perimeter of virtual triangle ABC which is formed by anchor node A,B and C. .
if neighboring_anchor_n>=3
gridmap=zeros(row_n,col_n);
grid_covered_flag=zeros(row_n,col_n);
for a=1:neighboring_anchor_n-2
for b=a+1:neighboring_anchor_n-1
for c=b+1:neighboring_anchor_n
neighboring_node_index=setdiff(find(neighbor_matrix(i,:)==1),neighboring_anchor_index([a b c]));
perim =sqrt(transpose((neighboring_anchor_n(1,1)-neighboring_anchor_n(2,1)).^2+(neighboring_anchor_n(1,2)-neighboring_anchor_n(2,2)).^2)+sqrt(transpose((neighboring_anchor_n(1,1)-neighboring_anchor_n(3,1)).^2+(neighboring_anchor_n(1,2)-neighboring_anchor_n(3,2)).^2)+sqrt(transpose((neighboring_anchor_n(2,1)-neighboring_anchor_n(3,1)).^2+(neighboring_anchor_n(2,2)-neighboring_anchor_n(3,2)).^2);
end
end
Thank you for your help in advance.
  4 个评论
Bob Thompson
Bob Thompson 2018-5-8
For future reference it's a bit easier if you paste the line itself, rather than the number, as many people post incomplete code, so your error message might say 'line 10' but it's actually line 6 of the posted code. I assume that is not the case here because you have posted a function, but for future reference.
James Tursa
James Tursa 2018-5-8
I don't see where neighboring_anchor or neighboring_anchor_index come from. What are they? What size are they? Is this a nested function?

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by