not enough arguments in zeros function,

15 visualizaciones (últimos 30 días)
malik shastry
malik shastry el 21 de Mayo de 2017
Respondida: Walter Roberson el 21 de Mayo de 2017
the code is :
function [] = my_scatter(N, L, coverage_range)
% ref input 50,50,20
% non-overlap distance > 5
% coverage_range ; % the shorter, the deeper tree
% == random coordination ==
distinct_BOUND = 5;
Z = zeros(N,2);
T = rand(1,2)*L;
Z(1,:) = T;
for i = 2:N
u = true;
v = false;
while u || v
T = rand(1,2)*L;
% u is true if new added node is too far to all node
u = true;
for j = 1:i-1
if pdist([T;Z(j,:)],'euclidean') < coverage_range
u = false;
end
end
% v is true if if new added node is too near to one node
v = false;
for j = 1:i-1
if pdist([T;Z(j,:)],'euclidean') < distinct_BOUND
v = true;
end
end
end
Z(i,:) = T;
end
% == figure raw nodes ==
figure;
scatter(Z(:,1),Z(:,2));
s = sprintf('N-%d,L-%d, cr-%d nodes', N, L, coverage_range);
title(s);
s1 = sprintf('N%d_L%d_cr-%d_nodes.png', N, L, coverage_range);
print(gcf,'-dpng',s1) ;
% == find root ==
m = mean(Z);
d = pdist([m;Z(1,:)],'euclidean');
r = Z(1,:);
root = 1;
for i = 2:N
if pdist([m;Z(i,:)],'euclidean') < d
d= pdist([m;Z(i,:)],'euclidean');
r = Z(i,:);
root = i;
end
end
Weight = zeros(N,N);
for i = 1:N
for j = 1:N
Weight(i,j) = pdist([Z(j,:) ; Z(i,:)],'euclidean');
end
end
% set a upper bound for distance, no connection for distance exceed it.
% == remove 'weak' link to generate mesh
for i = 1:N
for j = 1:N
if Weight(i,j) > coverage_range
Weight(i,j) = 0; % cancel 'too long' distance
end
end
end
% == shortest path alg ==
G = Weight;
G = sparse(G);
% root = 41;
[dist, path, pred] = graphshortestpath(G, root);
% Dijkstra,Time complexity is O(log(N)*E)
NUM_link = length(cell2mat(path));
G_adj = zeros(N,N);
for i = 1:N
for j = 1:N
if G(i,j)~=0
G_adj(i,j) = 1;
end
end
end
% == figure mesh ==
figure;
gplot(G_adj,Z);
s = sprintf('N-%d,L-%d, cr-%d mesh', N, L, coverage_range);
title(s);
s2 = sprintf('N%d_L%d_cr-%d_mesh.png', N, L, coverage_range);
print(gcf,'-dpng',s2) ;
depth_MAX = 20;
path_mat = zeros(N, depth_MAX);
depth = zeros(N,1);
for i = 1:N
t = cell2mat(path(i));
depth(i) = length(t);
t(depth_MAX)=0;
path_mat(i,:) = t;
end
Depth = max(depth); % in case multi output
Depth = Depth(1);
G_tree = zeros(N,N);
for i = 1:N
for j = 1:nnz(path_mat(i,:))-1
s = path_mat(i,j);
t = path_mat(i,j+1);
G_tree(s,t) = 1;
end
end
degree = zeros(1,N);
for i = 1:N
degree(i) = nnz( G_tree(i,:) );
end
degree_avg = mean(degree);
% == figure tree ==
figure;
gplot(G_tree,Z);
s = sprintf('N-%d,L-%d, cr-%d tree', N, L, coverage_range);
title(s);
s3 = sprintf('N%d_L%d_cr-%d_tree.png', N, L, coverage_range);
print(gcf,'-dpng',s3) ;
end
  1 comentario
Stephen23
Stephen23 el 21 de Mayo de 2017
@malik shastry: please edit your question and show us the complete error message. This means all of the red text.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Mayo de 2017
You cannot execute that code just by clicking on Run or using one of the execution menu entries. You need to go down to the command line and call it there, passing in three scalar parameters, the first of which is a positive integer. For example,
my_scatter(17, 89.14, 6.1235)

Más respuestas (0)

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by