Problem with size of a 0-by-1 empty matrix.
Show older comments
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);
Accepted Answer
More Answers (1)
Steven Lord
on 1 Aug 2019
2 votes
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.
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!