Borrar filtros
Borrar filtros

Create new matrix containing only subset of values from old matrix

9 visualizaciones (últimos 30 días)
Hi guys!
As a beginner I'm working with neural data in Matlab and I was hoping someone could help me with the following:
I have a matrix ('connectivity_matrix') of size 22 x 24 x 24 (22 dyads/subject pairs, 24 electrodes subject 1, 24 electrodes subject 2) which contains connectivity values.
Now, I want to create a new matrix ('new_connectivity_matrix') that for every dyad (first dimension of connectivity_matrix) only contains a specific subset of those connectivity values, from specific electrode combinations as indicated by the last two dimensions. Therefore, I created a binary matrix ('binary_matrix') of size 24 x 24 (24 electrodes subject 1, 24 electrodes subject 2) where the ones indicate which electrode combinations I want to keep in my new matrix. So to be clear, this binary matrix indicates which values (electrodes combinations) I want to keep in my new matrix voor every dyad.
I was thinking of looping over dyads (first dimension), and for every dyad elementwise multiple the 'binary_matrix' with the 'connectivity_matrix' so that for every dyad, the same electrode combinations as indicated by ones will be in my new matrix:
connectivity_matrix; % this is the connectivity matrix containing all dyads (22x24x24)
binary_matrix; % this is the binary matrix indicating which electrode combinations I want to keep in my new matrix (24x24)
new_connectivity_matrix = zeros(22,24,24); % initialize new matrix
for dyad = 1:22
new_connectivity_matrix = connectivity_matrix(dyad,:,:) .* binary_matrix(:,:)
end
I know something is not right.. The size of 'new_connectivity_matrix' for example is 24x24x24, while I assumed it should be 22x24x24?
I hope my explaination is a bit clear and someone can help me out! Thank you in advance!

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 8 de Jun. de 2021
Editada: Scott MacKenzie el 8 de Jun. de 2021
For the matrix multiplication, use squeeze so both matricies are 24x24, then assign the result to the corresponding 1st dimension of the new matrix:
for dyad = 1:22
new_connectivity_matrix(dyad,:,:) = squeeze(connectivity_matrix(dyad,:,:)) .* binary_matrix(:,:)
end

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by