Problem with size of a 0-by-1 empty matrix.

2 visualizaciones (últimos 30 días)
sam kamiab
sam kamiab el 1 de Ag. de 2019
Respondida: Steven Lord el 1 de Ag. de 2019
hi dear friends. For computing the jaccard similarity index of a graph's nodes I need to compute a pairwise intersection among their neighborhood matrix and find the number of common neighbors. for example (2, [1,4], [], 2) are neighbors of nodes 1 to 4 and node 3 is alone. The problem is that when I compute the intersection, the size of results for the alone node is [1x0 double] or [0x1 double] like this:
(Int)
[ 2] [1x0 double] [1x0 double] [ 2]
[1x0 double] [1x2 double] [0x1 double] [1x0 double]
[1x0 double] [0x1 double] [0x1 double] [1x0 double]
[ 2] [1x0 double] [1x0 double] [ 2]
and the size of [0x1 double] vector will be computed as 1 while the correct answer is 0 like this!
the size matrix:
1 0 0 1
0 2 1 0
0 1 1 0
1 0 0 1
I have the same problem with union, how can I fix this problem??
related part of my code is this:
[ii, jj] = ndgrid(1:Size) %Size=number of nodes
H=NeighborsS(L1,:); %%% I have a multiplex network and L1 is the layernumber
result= arrayfun(@(n) intersect(H{ii(n)},H{jj(n)}), 1:Size^2, 'uni', 0);
Int(:,:,L1) = reshape(result,Size,Size);
IntNum=cellfun('size',Inti,2);

Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Ag. de 2019
empty = cellfun(@isempty, result);
result(empty) = {zeros(0,0)}; %same size of emptiness for each empty result
Int(:,:,L1) = reshape(result,Size,Size);
IntNum = cellfun('size',Inti,2);

Más respuestas (1)

Steven Lord
Steven Lord el 1 de Ag. de 2019
You don't actually care about the size of the neighbors vector, you care about the number of neighbors. Use @numel instead of 'size' in your cellfun call.

Categorías

Más información sobre Matrices and Arrays 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