필터 지우기
필터 지우기

Summing up values in a matrix

조회 수: 1 (최근 30일)
Jonathan Bird
Jonathan Bird 2021년 1월 4일
댓글: Matt J 2021년 1월 4일
I have a 4D matrix, I(i,j,y,x) which has dimensions of 64 x 64 x 70 x 160. For each coordinate in y and x I'd like to sum all the values for I across i and j to form a 2D matrix I_y_x. i.e. I_y_x(0,0) = I(1,1,0,0)+I(1,2,0,0)+I(1,3,0,0) + .... + I(2,1,0,0) etc.
Thanks in advance

답변 (1개)

Matt J
Matt J 2021년 1월 4일
  댓글 수: 2
Jonathan Bird
Jonathan Bird 2021년 1월 4일
편집: Jonathan Bird 2021년 1월 4일
Thanks for your response, I tried I_y_x = sum(I,[1,2]); but I_y_x is now also a 4D matrix instead of 2D.
Matt J
Matt J 2021년 1월 4일
Just add a squeeze() or a reshape() operation
l=rand(64 , 64 , 70 , 160);
result=squeeze(sum(l,[1,2]));
whos result
Name Size Bytes Class Attributes result 70x160 89600 double

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by