-
-
Save rcassani/0a6472e548a3d059a93e57c57a811654 to your computer and use it in GitHub Desktop.
Brainstorm: Re-order NxN connectivity matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Export NxN connectivity node in tree as Matlab variable "connMat" | |
connMatNew = connMat; | |
nameRows = connMat.RowNames; | |
nameCols = connMat.RefRowNames; | |
if ~isequal(nameRows, nameCols) | |
error('Names for rows and columns MUST be the same') | |
end | |
nRows = length(nameRows); | |
% Expand connectivity matrix | |
connR = process_compress_sym('Expand', connMat.TF, nRows); | |
connR = reshape(connR, nRows, nRows); | |
connRNew = 0 * connR; | |
% New order (randowm for example) | |
rng(111); | |
ixsNew = randperm(nRows); | |
% Re-order | |
nameRowsNew = nameRows(ixsNew); | |
ixsCols = repmat(ixsNew, 1, nRows); | |
ixsRows = repelem(ixsNew, 1, nRows); | |
connRNew(:) = connR(sub2ind(size(connR), ixsRows, ixsCols)); | |
% Update fields | |
connMatNew.RowNames = nameRowsNew; | |
connMatNew.RefRowNames = nameRowsNew; | |
connMatNew.TF = process_compress_sym('Compress', connRNew(:)); | |
% Import the variable "connMatNew" to the NxN connectivity node in tree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment