Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

"index exceeds matrix dimension" error

1 view (last 30 days)
Kelil Mohammed
Kelil Mohammed on 8 May 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
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 Comments
Bob Thompson
Bob Thompson on 8 May 2018
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 on 8 May 2018
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?

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!