Cody

# Problem 410. Back to basics 20 - singleton dimensions

Solution 2765092

Submitted on 31 Jul 2020 by Jerry Wright
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 = rand(2,3,1,4); y_correct = 3; assert(isequal(ndims(remove_dims(x)),y_correct))

ans(:,:,1) = 0.0331 0.2049 0.6033 0.3496 0.6251 0.8263 ans(:,:,2) = 0.6175 0.5894 0.5316 0.6847 0.2419 0.7643 ans(:,:,3) = 0.5851 0.2794 0.7658 0.9531 0.9049 0.7539 ans(:,:,4) = 0.2739 0.1734 0.1957 0.9537 0.2628 0.9405

2   Pass
x = rand(2,3,4); y_correct = 3; assert(isequal(ndims(remove_dims(x)),y_correct))

ans(:,:,1) = 0.9289 0.5984 0.6534 0.5795 0.5376 0.7417 ans(:,:,2) = 0.3071 0.1453 0.4238 0.6314 0.7996 0.2191 ans(:,:,3) = 0.8564 0.8095 0.4308 0.3774 0.7283 0.7265 ans(:,:,4) = 0.1402 0.0687 0.6498 0.8554 0.5347 0.5714

3   Pass
x = rand(1,2,3,4,5); y_correct = 4; assert(isequal(ndims(remove_dims(x)),y_correct))

ans(:,:,1,1) = 0.7127 0.9215 0.0153 0.1163 0.2300 0.1817 ans(:,:,2,1) = 0.8110 0.0011 0.2740 0.5089 0.1177 0.7160 ans(:,:,3,1) = 0.8967 0.3335 0.9560 0.7141 0.4520 0.1254 ans(:,:,4,1) = 0.1420 0.9997 0.8534 0.6796 0.5565 0.7482 ans(:,:,1,2) = 0.0965 0.2166 0.6404 0.9712 0.5846 0.6860 ans(:,:,2,2) = 0.1341 0.3527 0.3694 0.8817 0.3824 0.3683 ans(:,:,3,2) = 0.9592 0.7345 0.0504 0.8564 0.3893 0.4550 ans(:,:,4,2) = 0.2802 0.2101 0.0463 0.5942 0.6330 0.3435 ans(:,:,1,3) = 0.4394 0.1029 0.6036 0.4031 0.6889 0.3417 ans(:,:,2,3) = 0.2168 0.4241 0.2043 0.8118 0.3626 0.3319 ans(:,:,3,3) = 0.1009 0.5826 0.2010 0.2780 0.0107 0.6713 ans(:,:,4,3) = 0.1121 0.6678 0.9439 0.2540 0.1289 0.9378 ans(:,:,1,4) = 0.3209 0.2782 0.0716 0.4762 0.0882 0.9667 ans(:,:,2,4) = 0.2746 0.0263 0.3631 0.8668 0.8984 0.1168 ans(:,:,3,4) = 0.7291 0.4709 0.1590 0.0279 0.7244 0.0962 ans(:,:,4,4) = 0.3787 0.1146 0.6988 0.9015 0.0963 0.0408 ans(:,:,1,5) = 0.6892 0.0291 0.3002 0.2120 0.4566 0.4252 ans(:,:,2,5) = 0.6368 0.4079 0.1176 0.2745 0.5343 0.8773 ans(:,:,3,5) = 0.7674 0.1286 0.4102 0.6368 0.0514 0.4086 ans(:,:,4,5) = 0.2032 0.4735 0.6452 0.5884 0.1810 0.9220