필터 지우기
필터 지우기

Create new matrix containing only subset of values from old matrix

조회 수: 9 (최근 30일)
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!

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 6월 8일
편집: Scott MacKenzie 2021년 6월 8일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by