Getting unique elements that form pairs in a Matrix
3 次查看(过去 30 天)
显示 更早的评论
Dear Everyone,
I have an issue.
I have a matrix of pairwise neuronal correlations. Which means if I have 137 neurons, my matrix is 137x137. So element (13,46) is the correlation between the 13th and the 46th neurons. I want to find all such pairs that have a correlation value of for e.g. > 0.5 (I want to test various thresholds). Then I just want to find the neurons that form these pairs. So if for e.g. the pairs are (13,46), (13,56), (46,56), the output needs to be - 13,46,56.
I first get the lower-half of my symmetric correlation matrix, and replace the upper half in this triangular matrix with NaNs. I also replace the diagonal 1s with NaNs.
And then I use [x,y]=find() to get the subscripts of the elements that exceed my threshold. I then use unique() on the x to get the unique neurons that form these pairs.
The correlation matrix has negative corrs and positive corrs. I only ask for let's say very high correlations. So I end up with around 900 pairs. When I ask for the unique neurons that form these pairs, I get 122 out of 137 for corrs > 0.5, but I get 127 for corrs > 0! This is weird right?
Here is my code -
sigCorrMat = tril(SU(iDataset).signalCorrelation); % Get the lower half
sigCorrMat(sigCorrMat==1) = NaN; % Replace diagonal with NaNs
sigCorrMat(sigCorrMat==0) = NaN; % Replace upper half with NaNs
[x,y]=find(sigCorrMat > thr(1) & sigCorrMat < thr(2)); % Find the pair IDs that satisfy the threshold criterion
allUnits = unique(x); % Get the units that form these pairs
I would be very grateful if someone could help me out. Thanks!
2 个评论
Guillaume
2017-10-25
编辑:Guillaume
2017-10-25
I get 122 out of 137 for corrs > 0.5, but I get 127 for corrs > 0! This is weird right?
Why is it weird? the set of numbers > 0 is guaranteed to have at least as many elements as the set of numbers > 0.5
Note that comparing to 1 to identify diagonal elements and 0 to identify upper half looks risky. What if you have 1s or 0s in the lower half? Safer (and possibly faster) would be to filter the logical array you pass to find:
sigCorrMat = SU(iDataset).signalCorrelation;
iscorr = sigCorrMat > thr(1) & sigCorrMat < thr(2);
[row, col] = find(tril(iscorr, -1)); %tril(x, -1) only keeps the true values below the diagonal
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Neural Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!