Clear Filters
Clear Filters

How to create a weighted adjacency matrix from 3d array?

1 view (last 30 days)
Hi,
I have a 3d array like 114x114x9 (represents connectivity matrix) How can I create a weighted (nxn) adjacency matrix from this array? In order to use Brain Connectivity Toolbox, I have to obtain adjacency matrix. I specifically need to get the weighted one.
Thanks in advance.

Answers (1)

Shubham
Shubham on 12 Feb 2024
Hi Hande,
To create a weighted adjacency matrix from a 3D array, you need to aggregate the connectivity information across the third dimension in a way that makes sense for your specific application. A common approach is to take the average or the sum of the connectivity values across the third dimension to collapse it into a 2D weighted adjacency matrix.
Given a 3D array of size 114x114x9, where each 114x114 slice represents a connectivity matrix for a different condition or time point, you might want to average these to get a single weighted adjacency matrix that represents the average connectivity.
Here's how you can do it:
% Assuming 'connectivity_3d' is your 3D array of size 114x114x9
connectivity_3d = rand(114, 114, 9); % replace this with your actual 3D array
% Create the weighted adjacency matrix by averaging across the third dimension
weighted_adjacency_matrix = mean(connectivity_3d, 3);
% Since the adjacency matrix should be symmetric, you can enforce this by symmetrizing the matrix
weighted_adjacency_matrix = (weighted_adjacency_matrix + weighted_adjacency_matrix') / 2;
% If the diagonal contains non-zero values and you need it to be zero, you can set it to zero
for i = 1:size(weighted_adjacency_matrix, 1)
weighted_adjacency_matrix(i, i) = 0;
end
% Now 'weighted_adjacency_matrix' is your weighted adjacency matrix ready for use
This code snippet will give you a weighted adjacency matrix that you can use with the Brain Connectivity Toolbox (BCT). If you need to apply a different method for collapsing the third dimension (e.g., taking the maximum or applying a threshold), you should adjust the aggregation function accordingly.
Please ensure that the resulting weighted adjacency matrix conforms to the requirements of the BCT and the specific measures you intend to calculate. For instance, some measures might require the matrix to be binary, while others can work with weighted connections. If you need a binary adjacency matrix, you would have to apply a threshold to the weighted matrix to determine which connections are considered significant.

Categories

Find more on Shifting and Sorting Matrices 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!