필터 지우기
필터 지우기

How to make three dimension matrix indexed sum return summation across the third dimension

조회 수: 1 (최근 30일)
I want to get a 2d matrix after summing 3d matrix based on an index. Or how can I project the indexed sum to a 2d matrix? The example below gives only the sum for the indexes.
datax = rand(3,3,5);
cr1 = int32(randi([0, 1], [1, 45]));
cr1 = reshape(cr1,3,3,5);
cr2 = int32(randi([0, 1], [1, 45]));
cr2 = reshape(cr2,3,3,5);
inddata = find(cr1==1 & cr2==0);
sum(datax(inddata),2)

채택된 답변

Jan
Jan 2021년 5월 14일
datax = rand(3,3,5);
cr1 = rand(3,3,5) > 0.5;
cr2 = rand(3,3,5) > 0.5;
ignore = (~cr1 | cr2);
result = sum(datax .* ignore, 3)
result = 3×3
1.2499 1.8071 1.0860 1.8841 1.6616 2.8713 2.8635 1.1758 2.0541
If you really need int32 data:
cr1 = randi([0, 1], size(datax), 'int32');
cr2 = randi([0, 1], size(datax), 'int32');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by