필터 지우기
필터 지우기

How to reset the 'lower triangle' of a 3 dimentional matrix

조회 수: 3 (최근 30일)
JazzMusic
JazzMusic 2016년 11월 28일
댓글: JazzMusic 2016년 11월 28일
Hi,
I need to reset the 'lower triangle' of a 3 dimentional matrix. This means, that if the original matrix is:
C(:,:,1) = [1 2 3 ; 2 4 6 ; 3 6 9]
C(:,:,2) = [2 4 6 ; 4 8 12 ; 6 12 18]
C(:,:,3) = [3 6 9 ; 6 12 18 ; 9 18 27]
Then the resulting matrix should be:
C(:,:,1) = [1 2 3 ; 2 4 6 ; 3 6 9]
C(:,:,2) = [0 0 0 ; 4 8 12 ; 6 12 18]
C(:,:,3) = [0 0 0 ; 0 0 0 ; 9 18 27]
Any idea how such a thing csn be done? (My original 3 dim matrix is large)
Thanks!

채택된 답변

Ryan Smith
Ryan Smith 2016년 11월 28일
Brute force method:
D3 = length(C(1,1,:));
D2 = length(C(1,:,1));
D1 = length(C(:,1,1));
for i = 2:D1
for j = 1:i-1
for k = 1:i-1
C(i,j,k) = 0;
end
end
end
Above provides [1 2 3; 0 4 6; 0 0 9] ; [2 4 6; 4 8 12; 0 0 18]; [3 6 9; 6 12 18; 9 18 27], which I believe would be the 'true' lower triangle. Don't quote me on that. To get what you requested, via 'brute force':
b = zeros([1 length(C(1,:,1))]);
for k = 2:D3
for i = 1:k-1
C(i,:,k) = b;
end
end

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by