Three-dimensional lower triangular Matrix

8 views (last 30 days)
Hi guys,I want creat a 3D lower triangular Matrix such as the size of 100*100*100. I know to use the tril function to creat a 2D lower triangular Matrix . Is there any function that can help me solve this problem? Thanks.

Accepted Answer

DGM
DGM on 14 Apr 2021
Not sure if this is what you're asking, but:
A = randi(89,10,10,2)+10; % test array
mask = tril(ones(size(A,1),size(A,2))); % make a mask
B = bsxfun(@times,A,mask) % bsxfun() isn't strictly necessary post-R2016b
gives:
B(:,:,1) =
34 0 0 0 0 0 0 0 0 0
78 93 0 0 0 0 0 0 0 0
90 17 64 0 0 0 0 0 0 0
75 37 21 28 0 0 0 0 0 0
47 63 56 20 20 0 0 0 0 0
94 29 85 37 63 85 0 0 0 0
33 67 92 46 36 82 99 0 0 0
58 82 55 48 24 92 54 76 0 0
95 55 35 38 11 23 72 57 59 0
34 68 69 72 36 55 47 82 64 26
B(:,:,2) =
22 0 0 0 0 0 0 0 0 0
89 40 0 0 0 0 0 0 0 0
14 38 13 0 0 0 0 0 0 0
72 90 78 54 0 0 0 0 0 0
76 32 73 33 44 0 0 0 0 0
49 38 30 93 30 28 0 0 0 0
44 47 71 52 30 65 75 0 0 0
98 74 60 33 57 59 58 55 0 0
46 23 86 49 49 25 33 48 86 0
50 88 60 73 76 11 92 65 90 59

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!