Cody

# Problem 410. Back to basics 20 - singleton dimensions

Solution 1813363

Submitted on 12 May 2019
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   Fail
x = rand(2,3,1,4); y_correct = 3; assert(isequal(ndims(remove_dims(x)),y_correct))

x(:,:,1,1) = 0.5851 0.6741 0.7215 0.0395 0.9904 0.0111 x(:,:,1,2) = 0.0752 0.0524 0.5544 0.0709 0.0014 0.8325 x(:,:,1,3) = 0.5049 0.7442 0.1694 0.6918 0.8793 0.8786 x(:,:,1,4) = 0.8512 0.8208 0.4217 0.0373 0.5498 0.9468

Assertion failed.

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

x(:,:,1) = 0.4555 0.6581 0.0206 0.4698 0.3514 0.5962 x(:,:,2) = 0.3521 0.9498 0.6937 0.6597 0.2883 0.5113 x(:,:,3) = 0.3235 0.3827 0.5094 0.5893 0.5415 0.4289 x(:,:,4) = 0.8644 0.3707 0.8421 0.7225 0.1731 0.5106

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

x(:,:,1,1,1) = 0.7679 0.4390 x(:,:,2,1,1) = 0.8333 0.8460 x(:,:,3,1,1) = 0.6667 0.6704 x(:,:,1,2,1) = 0.9433 0.0478 x(:,:,2,2,1) = 0.3517 0.0160 x(:,:,3,2,1) = 0.6896 0.0240 x(:,:,1,3,1) = 0.0738 0.5656 x(:,:,2,3,1) = 0.4761 0.0271 x(:,:,3,3,1) = 0.2674 0.8571 x(:,:,1,4,1) = 0.2769 0.9755 x(:,:,2,4,1) = 0.2856 0.9216 x(:,:,3,4,1) = 0.6311 0.8041 x(:,:,1,1,2) = 0.8994 0.1003 x(:,:,2,1,2) = 0.6053 0.8187 x(:,:,3,1,2) = 0.0723 0.7705 x(:,:,1,2,2) = 0.2344 0.9140 x(:,:,2,2,2) = 0.2569 0.6869 x(:,:,3,2,2) = 0.7366 0.5427 x(:,:,1,3,2) = 0.4943 0.1000 x(:,:,2,3,2) = 0.7452 0.2027 x(:,:,3,3,2) = 0.5976 0.9458 x(:,:,1,4,2) = 0.0462 0.1183 x(:,:,2,4,2) = 0.8037 0.6526 x(:,:,3,4,2) = 0.5161 0.5713 x(:,:,1,1,3) = 0.4471 0.6554 x(:,:,2,1,3) = 0.8618 0.1769 x(:,:,3,1,3) = 0.3957 0.0227 x(:,:,1,2,3) = 0.9996 0.0772 x(:,:,2,2,3) = 0.8618 0.0428 x(:,:,3,2,3) = 0.5451 0.1903 x(:,:,1,3,3) = 0.1964 0.8739 x(:,:,2,3,3) = 0.5271 0.6737 x(:,:,3,3,3) = 0.9213 0.2038 x(:,:,1,4,3) = 0.6787 0.3756 x(:,:,2,4,3) = 0.9106 0.7629 x(:,:,3,4,3) = 0.8561 0.0805 x(:,:,1,1,4) = 0.3135 0.0955 x(:,:,2,1,4) = 0.8892 0.0219 x(:,:,3,1,4) = 0.7226 0.3221 x(:,:,1,2,4) = 0.1251 0.5144 x(:,:,2,2,4) = 0.5347 0.3261 x(:,:,3,2,4) = 0.8424 0.8625 x(:,:,1,3,4) = 0.3674 0.3880 x(:,:,2,3,4) = 0.8935 0.9737 x(:,:,3,3,4) = 0.2027 0.8504 x(:,:,1,4,4) = 0.3954 0.5374 x(:,:,2,4,4) = 0.7753 0.5668 x(:,:,3,4,4) = 0.2862 0.9086 x(:,:,1,1,5) = 0.4812 0.4173 x(:,:,2,1,5) = 0.4122 0.1752 x(:,:,3,1,5) = 0.3370 0.8997 x(:,:,1,2,5) = 0.1357 0.9158 x(:,:,2,2,5) = 0.7687 0.6977 x(:,:,3,2,5) = 0.4970 0.5264 x(:,:,1,3,5) = 0.2975 0.0454 x(:,:,2,3,5) = 0.0737 0.0236 x(:,:,3,3,5) = 0.9258 0.9013 x(:,:,1,4,5) = 0.9108 0.3886 x(:,:,2,4,5) = 0.7647 0.5307 x(:,:,3,4,5) = 0.2888 0.5560

Assertion failed.