Cody

# Problem 1704. Triangular matrices in 3D array

Solution 1690268

Submitted on 11 Dec 2018 by Augusto Mazzei
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x(:,:,1) = [1 2 3;4 5 6;7 8 9]; x(:,:,2) = [1 4 7;2 5 8;3 6 9]; x(:,:,3) = [1 2 3;1 2 3;1 2 3]; y_correct(:,:,1) = [1 0 0;4 5 0;7 8 9]; y_correct(:,:,2) = [1 0 0;2 5 0;3 6 9]; y_correct(:,:,3) = [1 0 0;1 2 0;1 2 3]; assert(isequal(tril3(x),y_correct))

x(:,:,1) = 1 0 0 4 5 0 7 8 9 x(:,:,2) = 1 0 0 2 5 0 3 6 9 x(:,:,3) = 1 0 0 1 2 0 1 2 3

2   Pass
x = cumsum(ones(3,3,50)); y_correct = repmat([1 0 0;2 2 0; 3 3 3],[1,1,50]); assert(isequal(tril3(x),y_correct))

x(:,:,1) = 1 0 0 2 2 0 3 3 3 x(:,:,2) = 1 0 0 2 2 0 3 3 3 x(:,:,3) = 1 0 0 2 2 0 3 3 3 x(:,:,4) = 1 0 0 2 2 0 3 3 3 x(:,:,5) = 1 0 0 2 2 0 3 3 3 x(:,:,6) = 1 0 0 2 2 0 3 3 3 x(:,:,7) = 1 0 0 2 2 0 3 3 3 x(:,:,8) = 1 0 0 2 2 0 3 3 3 x(:,:,9) = 1 0 0 2 2 0 3 3 3 x(:,:,10) = 1 0 0 2 2 0 3 3 3 x(:,:,11) = 1 0 0 2 2 0 3 3 3 x(:,:,12) = 1 0 0 2 2 0 3 3 3 x(:,:,13) = 1 0 0 2 2 0 3 3 3 x(:,:,14) = 1 0 0 2 2 0 3 3 3 x(:,:,15) = 1 0 0 2 2 0 3 3 3 x(:,:,16) = 1 0 0 2 2 0 3 3 3 x(:,:,17) = 1 0 0 2 2 0 3 3 3 x(:,:,18) = 1 0 0 2 2 0 3 3 3 x(:,:,19) = 1 0 0 2 2 0 3 3 3 x(:,:,20) = 1 0 0 2 2 0 3 3 3 x(:,:,21) = 1 0 0 2 2 0 3 3 3 x(:,:,22) = 1 0 0 2 2 0 3 3 3 x(:,:,23) = 1 0 0 2 2 0 3 3 3 x(:,:,24) = 1 0 0 2 2 0 3 3 3 x(:,:,25) = 1 0 0 2 2 0 3 3 3 x(:,:,26) = 1 0 0 2 2 0 3 3 3 x(:,:,27) = 1 0 0 2 2 0 3 3 3 x(:,:,28) = 1 0 0 2 2 0 3 3 3 x(:,:,29) = 1 0 0 2 2 0 3 3 3 x(:,:,30) = 1 0 0 2 2 0 3 3 3 x(:,:,31) = 1 0 0 2 2 0 3 3 3 x(:,:,32) = 1 0 0 2 2 0 3 3 3 x(:,:,33) = 1 0 0 2 2 0 3 3 3 x(:,:,34) = 1 0 0 2 2 0 3 3 3 x(:,:,35) = 1 0 0 2 2 0 3 3 3 x(:,:,36) = 1 0 0 2 2 0 3 3 3 x(:,:,37) = 1 0 0 2 2 0 3 3 3 x(:,:,38) = 1 0 0 2 2 0 3 3 3 x(:,:,39) = 1 0 0 2 2 0 3 3 3 x(:,:,40) = 1 0 0 2 2 0 3 3 3 x(:,:,41) = 1 0 0 2 2 0 3 3 3 x(:,:,42) = 1 0 0 2 2 0 3 3 3 x(:,:,43) = 1 0 0 2 2 0 3 3 3 x(:,:,44) = 1 0 0 2 2 0 3 3 3 x(:,:,45) = 1 0 0 2 2 0 3 3 3 x(:,:,46) = 1 0 0 2 2 0 3 3 3 x(:,:,47) = 1 0 0 2 2 0 3 3 3 x(:,:,48) = 1 0 0 2 2 0 3 3 3 x(:,:,49) = 1 0 0 2 2 0 3 3 3 x(:,:,50) = 1 0 0 2 2 0 3 3 3

3   Pass
x = cumsum(ones(5,5,100),2); y_correct = repmat(tril(cumsum(ones(5,5),2)),[1,1,100]); assert(isequal(tril3(x),y_correct))

x(:,:,1) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 x(:,:,2) = 1 0 0 0 0 1 2 0 0 0 1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 3 4 0 1 2 3 4 5 x(:,:,54) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 x(:,:,55) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 x(:,:,56) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 x(:,:,57) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 x(:,:,58) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 x(:,:,59) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2...

4   Pass
x = rand([1 1 400]); y_correct = x; assert(isequal(tril3(x),y_correct))

x(:,:,1) = 0.9977 x(:,:,2) = 0.2456 x(:,:,3) = 0.9947 x(:,:,4) = 0.7845 x(:,:,5) = 0.4571 x(:,:,6) = 0.6107 x(:,:,7) = 0.3819 x(:,:,8) = 0.3968 x(:,:,9) = 0.8968 x(:,:,10) = 0.0931 x(:,:,11) = 0.6191 x(:,:,12) = 0.2882 x(:,:,13) = 0.2323 x(:,:,14) = 0.1906 x(:,:,15) = 0.8890 x(:,:,16) = 0.2192 x(:,:,17) = 0.3283 x(:,:,18) = 0.0853 x(:,:,19) = 0.2833 x(:,:,20) = 0.8170 x(:,:,21) = 0.3195 x(:,:,22) = 0.7165 x(:,:,23) = 0.5007 x(:,:,24) = 0.1280 x(:,:,25) = 0.1223 x(:,:,26) = 0.0600 x(:,:,27) = 0.5730 x(:,:,28) = 0.3158 x(:,:,29) = 0.0472 x(:,:,30) = 0.5454 x(:,:,31) = 0.6231 x(:,:,32) = 0.9376 x(:,:,33) = 0.4090 x(:,:,34) = 0.3896 x(:,:,35) = 0.1360 x(:,:,36) = 0.6507 x(:,:,37) = 0.9509 x(:,:,38) = 0.5009 x(:,:,39) = 0.2750 x(:,:,40) = 0.4428 x(:,:,41) = 0.6853 x(:,:,42) = 0.5846 x(:,:,43) = 0.9492 x(:,:,44) = 0.3646 x(:,:,45) = 0.2534 x(:,:,46) = 0.7454 x(:,:,47) = 0.7344 x(:,:,48) = 0.1366 x(:,:,49) = 0.7463 x(:,:,50) = 0.1459 x(:,:,51) = 0.3657 x(:,:,52) = 0.9511 x(:,:,53) = 0.9248 x(:,:,54) = 0.6720 x(:,:,55) = 0.9923 x(:,:,56) = 0.9766 x(:,:,57) = 0.2492 x(:,:,58) = 0.1282 x(:,:,59) = 0.0204 x(:,:,60) = 0.7908 x(:,:,61) = 0.7522 x(:,:,62) = 0.1263 x(:,:,63) = 0.4816 x(:,:,64) = 0.0459 x(:,:,65) = 0.8525 x(:,:,66) = 0.8939 x(:,:,67) = 0.1294 x(:,:,68) = 0.6397 x(:,:,69) = 0.9117 x(:,:,70) = 0.5925 x(:,:,71) = 0.5593 x(:,:,72) = 0.7841 x(:,:,73) = 0.9439 x(:,:,74) = 0.9200 x(:,:,75) = 0.0371 x(:,:,76) = 0.6822 x(:,:,77) = 0.5866 x(:,:,78) = 0.8731 x(:,:,79) = 0.7359 x(:,:,80) = 0.5205 x(:,:,81) = 0.3564 x(:,:,82) = 0.2426 x(:,:,83) = 0.5917 x(:,:,84) = 0.4266 x(:,:,85) = 0.8024 x(:,:,86) = 0.0915 x(:,:,87) = 0.1359 x(:,:,88) = 0.3639 x(:,:,89) = 0.5639 x(:,:,90) = 0.6354 x(:,:,91) = 0.2148 x(:,:,92) = 0.2067 x(:,:,93) = 0.1548 x(:,:,94) = 0.0849 x(:,:,95) = 0.9603 x(:,:,96) = 0.0701 x(:,:,97) = 0.2890 x(:,:,98) = 0.4900 x(:,:,99) = 0.7758 x(:,:,100) = 0.9987 x(:,:,101) = 0.8828 x(:,:,102) = 0.7135 x(:,:,103) = 0.6931 x(:,:,104) = 0.9393 x(:,:,105) = 0.3330 x(:,:,106) = 0.2068 x(:,:,107) = 0.3540 x(:,:,108) = 0.9386 x(:,:,109) = 0.2017 x(:,:,110) = 0.8737 x(:,:,111) = 0.5999 x(:,:,112) = 0.2126 x(:,:,113) = 0.7353 x(:,:,114) = 0.1766 x(:,:,115) = 0.6863 x(:,:,116) = 0.1440 x(:,:,117) = 0.4215 x(:,:,118) = 0.6060 x(:,:,119) = 0.2454 x(:,:,120) = 0.5483 x(:,:,121) = 0.8614 x(:,:,122) = 0.8371 x(:,:,123) = 0.3606 x(:,:,124) = 0.7395 x(:,:,125) = 0.5784 x(:,:,126) = 0.8920 x(:,:,127) = 0.5940 x(:,:,128) = 0.8474 x(:,:,129) = 0.1726 x(:,:,130) = 0.4152 x(:,:,131) = 0.8566 x(:,:,132) = 0.4802 x(:,:,133) = 0.6745 x(:,:,134) = 0.1905 x(:,:,135) = 0.8383 x(:,:,136) = 0.3284 x(:,:,137) = 0.4238 x(:,:,138) = 0.7718 x(:,:,139) = 0.1934 x(:,:,140) = 0.4162 x(:,:,141) = 0.3965 x(:,:,142) = 0.0958 x(:,:,143) = 0.4633 x(:,:,144) = 0.9969 x(:,:,145) = 0.5690 x(:,:,146) = 0.8028 x(:,:,147) = 0.4169 x(:,:,148) = 0.5667 x(:,:,149) = 0.9535 x(:,:,150) = 0.6720 x(:,:,151) = 0.8577 x(:,:,152) = 0.7543 x(:,:,153) = 0.8532 x(:,:,154) = 0.7169 x(:,:,155) = 0.5196 x(:,:,156) = 0.7231 x(:,:,157) = 0.8952 x(:,:,158) = 0.3879 x(:,:,159) = 0.5604 x(:,:,160) = 0.4220 x(:,:,161) = 0.5191 x(:,:,162) = 0.6944 x(:,:,163) = 0.7325 x(:,:,164) = 0.2807 x(:,:,165) = 0.7065 x(:,:,166) = 0.6035 x(:,:,167) = 0.0734 x(:,:,168) = 0.8742 x(:,:,169) = 0.9927 x(:,:,170) = 0.2542 x(:,:,171) = 0.4526 x(:,:,172) = 0.7956 x(:,:,173) = 0.4485 x(:,:,174) = 0.1931 x(:,:,175) = 0.1778 x(:,:,176) = 0.9318 x(:,:,177) = 0.3441 x(:,:,178) = 0.9242 x(:,:,179) = 0.1898 x(:,:,180) = 0.7815 x(:,:,181) = 0.5341 x(:,:,182) = 0.0347 x(:,:,183) = 0.5007 x(:,:,184) = 0.0075 x(:,:,185) = 0.8698 x(:,:,186) = 0.3085 x(:,:,187) = 0.3972 x(:,:,188) = 0.0610 x(:,:,189) = 0.0197 x(:,:,190) = 0.6310 x(:,:,191) = 0.7320 x(:,:,192) = 0.0233 x(:,:,193) = 0.5305 x(:,:,194) = 0.8842 x(:,:,195) = 0.2375 x(:,:,196) = 0.0749 x(:,:,197) = 0.7463 x(:,:,198) = 0.0266 x(:,:,199) = 0.3705 x(:,:,200) = 7.3514e-04 x(:,:,201) = 0.1504 x(:,:,202) = 0.0273 x(:,:,203) = 0.3083 x(:,:,204) = 0.8354 x(:,:,205) = 0.5195 x(:,:,206) = 0.9622 x(:,:,207) = 0.4852 x(:,:,208) = 0.8048 x(:,:,209) = 0.6797 x(:,:,210) = 0.6638 x(:,:,211) = 0.6137 x(:,:,212) = 0.9866 x(:,:,213) = 0.4441 x(:,:,214) = 0.1173 x(:,:,215) = 0.9157 x(:,:,216) = 0.6594 x(:,:,217) = 0.8380 x(:,:,218) = 0.7761 x(:,:,219) = 0.1164 x(:,:,220) = 0.7858 x(:,:,221) = 0.5402 x(:,:,222) = 0.5895 x(:,:,223) = 0.7342 x(:,:,224) = 0.8551 x(:,:,225) = 0.2043 x(:,:,226) = 0.4358 x(:,:,227) = 0.7739 x(:,:,228) = 0.7828 x(:,:,229) = 0.1091 x(:,:,230) = 0.5373 x(:,:,231) = 0.0799 x(:,:,232) = 0.1363 x(:,:,233) = 0.9006 x(:,:,234) = 0.0142 x(:,:,235) = 0.7368 x(:,:,236) = 0.6950 x(:,:,237) = 0.4506 x(:,:,238) = 0.7576 x(:,:,239) = 0.9004 x(:,:,240) = 0.1772 x(:,:,241) = 0.7782 x(:,:,242) = 0.9407 x(:,:,243) = 0.7963 x(:,:,244) = 0.0949 x(:,:,245) = 0.7846 x(:,:,246) = 0.3138 x(:,:,247) = 0.0488 x(:,:,248) = 0.5447 x(:,:,249) = 0.4150 x(:,:,250) = 0.8058 x(:,:,251) = 0.5550 x(:,:,252) = 0.2342 x(:,:,253) = 0.2979 x(:,:,254) = 0.9915 x(:,:,255) = 0.8367 x(:,:,256) = 0.0603 x(:,:,257) = 0.6419 x(:,:,258) = 0.5188 x(:,:,259) = 0.9591 x(:,:,260) = 0.3332 x(:,:,261) = 0.2933 x(:,:,262) = 0.8061 x(:,:,263) = 0.2961 x(:,:,264) = 0.9754 x(:,:,265) = 0.4145 x(:,:,266) = 0.4797 x(:,:,267) = 0.7830 x(:,:,268) = 0.9317 x(:,:,269) = 0.3230 x(:,:,270) = 0.2085 x(:,:,271) = 0.3164 x(:,:,272) = 0.9099 x(:,:,273) = 0.1182 x(:,:,274) = 0.1675 x(:,:,275) = 0.2084 x(:,:,276) = 0.6777 x(:,:,277) = 0.3183 x(:,:,278) = 0.5278 x(:,:,279) = 0.0306 x(:,:,280) = 0.6416 x(:,:,281) = 0.6355 x(:,:,282) = 0.5864 x(:,:,283) = 0.6804 x(:,:,284) = 0.7943 x(:,:,285) = 0.3087 x(:,:,286) = 0.0675 x(:,:,287) = 0.4331 x(:,:,288) = 0.3986 x(:,:,289) = 0.0890 x(:,:,290) = 0.3977 x(:,:,291) = 0.1280 x(:,:,292) = 0.2081 x(:,:,293) = 0.0286 x(:,:,294) = 0.3151 x(:,:,295) = 0.1095 x(:,:,296) = 0.0923 x(:,:,297) = 0.4131 x(:,:,298) = 0.6498 x(:,:,299) = 0.1726 x(:,:,300) = 0.0508 x(:,:,301) = 0.0950 x(:,:,302) = 0.6102 x(:,:,303) = 0.8368 x(:,:,304) = 0.8513 x(:,:,305) = 0.7713 x(:,:,306) = 0.5701 x(:,:,307) = 0.6932 x(:,:,308) = 0.4791 x(:,:,309) = 0.1454 x(:,:,310) = 0.8080 x(:,:,311) = 0.5379 x(:,:,312) = 0.8443 x(:,:,313) = 0.1676 x(:,:,314) = 0.8319 x(:,:,315) = 0.5873 x(:,:,316) = 0.4380 x(:,:,317) = 0.4663 x(:,:,318) = 0.5560 x(:,:,319) = 0.7658 x(:,:,320) = 0.5736 x(:,:,321) = 0.1417 x(:,:,322) = 0.4952 x(:,:,323) = 0.7237 x(:,:,324) = 0.9583 x(:,:,325) = 0.9601 x(:,:,326) = 0.4104 x(:,:,327) = 0.6123 x(:,:,328) = 0.8090 x(:,:,329) = 0.2199 x(:,:,330) = 0.3217 x(:,:,331) = 0.9369 x(:,:,332) = 0.5943 x(:,:,333) = 0.4609 x(:,:,334) = 0.6734 x(:,:,335) = 0.7157 x(:,:,336) = 0.7137 x(:,:,337) = 0.2164 x(:,:,338) = 0.3485 x(:,:,339) = 0.0165 x(:,:,340) = 0.4494 x(:,:,341) = 0.3884 x(:,:,342) = 0.0232 x(:,:,343) = 0.0637 x(:,:,344) = 0.3598 x(:,:,345) = 0.4140 x(:,:,346) = 0.8644 x(:,:,347) = 0.0094 x(:,:,348) = 0.2336 x(:,:,349) = 0.1235 x(:,:,350) = 0.5809 x(:,:,351) = 0.0353 x(:,:,352) = 0.6659 x(:,:,353) = 0.3162 x(:,:,354) = 0.6400 x(:,:,355) = 0.3620 x(:,:,356) = 0.1233 x(:,:,357) = 0.4113 x(:,:,358) = 0.1630 x(:,:,359) = 0.7883 x(:,:,360) = 0.2134 x(:,:,361) = 0.2664 x(:,:,362) = 0.3885 x(:,:,363) = 0.5501 x(:,:,364) = 0.0315 x(:,:,365) = 0.8308 x(:,:,366) = 0.6179 x(:,:,367) = 0.1347 x(:,:,368) = 0.1353 x(:,:,369) = 0.6931 x(:,:,370) = 0.7234 x(:,:,371) = 0.9299 x(:,:,372) = 0.9456 x(:,:,373) = 0.9128 x(:,:,374) = 0.2609 x(:,:,3...

5   Pass
x = reshape(1:40,[2,2,10]); y_correct(:,:,1) = [1 0;2 4]; y_correct(:,:,2) = [5 0;6 8]; y_correct(:,:,3) = [9 0;10 12]; y_correct(:,:,4) = [13 0;14 16]; y_correct(:,:,5) = [17 0;18 20]; y_correct(:,:,6) = [21 0;22 24]; y_correct(:,:,7) = [25 0;26 28]; y_correct(:,:,8) = [29 0;30 32]; y_correct(:,:,9) = [33 0;34 36]; y_correct(:,:,10) = [37 0;38 40]; assert(isequal(tril3(x),y_correct))

x(:,:,1) = 1 0 2 4 x(:,:,2) = 5 0 6 8 x(:,:,3) = 9 0 10 12 x(:,:,4) = 13 0 14 16 x(:,:,5) = 17 0 18 20 x(:,:,6) = 21 0 22 24 x(:,:,7) = 25 0 26 28 x(:,:,8) = 29 0 30 32 x(:,:,9) = 33 0 34 36 x(:,:,10) = 37 0 38 40

6   Pass
x = randi([0 1],[4,4,5]); y_correct(:,:,1) = tril(x(:,:,1)); y_correct(:,:,2) = tril(x(:,:,2)); y_correct(:,:,3) = tril(x(:,:,3)); y_correct(:,:,4) = tril(x(:,:,4)); y_correct(:,:,5) = tril(x(:,:,5)); assert(isequal(tril3(x),y_correct))

x(:,:,1) = 1 0 0 0 0 1 0 0 1 0 1 0 0 1 1 1 x(:,:,2) = 1 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 x(:,:,3) = 1 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 x(:,:,4) = 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 x(:,:,5) = 1 0 0 0 0 0 0 0 0 1 1 0 0 1 1 1

### Community Treasure Hunt

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

Start Hunting!