フィルターのクリア

I have used the following code to create a wsn virtual structure with 4*4 grid-cells and have deployed 100 nodes in it. Now i want to select a wsn area-header which would be in the center of the whole wsn virtual structure. How could that be done. Pl

3 ビュー (過去 30 日間)
I have used the following code to create a wsn virtual structure with 4*4 grid-cells and have deployed 100 nodes in it. Now i want to select a wsn area-header which would be in the center of the whole wsn virtual structure. How could that be done. Please help.
% WSN Grid structure with 4*4 cells made
NrGrid = 4;
x = linspace(0, 100, NrGrid+1);
[X,Y] = meshgrid(x);
figure(1)
plot(X,Y,'k')
hold on
plot(Y,X,'k')
hold off
set(gca, 'Box','off', 'XTick',[], 'YTick',[])
axis square
% grid formation ends
% Nodes deployment started
NrGrid = 4;
coords = rand(100,2) * NrGrid + 1;
scatter(coords(:,1),coords(:,2));
set(gca, 'XTick', 1:NrGrid+1, 'YTick', 1:NrGrid+1)
grid on

採用された回答

Walter Roberson
Walter Roberson 2015 年 6 月 13 日
[mindist, minidx] = sqrt(sum((coords - NrGrid/2).^2,2));
coords(minidx,:) is the closest node to the center.
  2 件のコメント
Parveen verma
Parveen verma 2015 年 6 月 14 日
When i run the code,following error comes:-
??? Error using ==> sqrt Too many output arguments.
Error in ==> techworks at 48 [mindist, minidx] = sqrt(sum((coords - NrGrid/2).^2,2));
Please help.
Walter Roberson
Walter Roberson 2015 年 6 月 24 日
[mindist, minidx] = min(sqrt(sum((coords - NrGrid/2).^2,2)));

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by