Cody

# Problem 410. Back to basics 20 - singleton dimensions

Solution 171238

Submitted on 1 Dec 2012 by Francis Esmonde-White
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))

``` x(:,:,1) = 0.8147 0.1270 0.6324 0.9058 0.9134 0.0975 x(:,:,2) = 0.2785 0.9575 0.1576 0.5469 0.9649 0.9706 x(:,:,3) = 0.9572 0.8003 0.4218 0.4854 0.1419 0.9157 x(:,:,4) = 0.7922 0.6557 0.8491 0.9595 0.0357 0.9340 ```

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

``` x(:,:,1) = 0.6787 0.7431 0.6555 0.7577 0.3922 0.1712 x(:,:,2) = 0.7060 0.2769 0.0971 0.0318 0.0462 0.8235 x(:,:,3) = 0.6948 0.9502 0.4387 0.3171 0.0344 0.3816 x(:,:,4) = 0.7655 0.1869 0.4456 0.7952 0.4898 0.6463 ```

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

``` x(:,:,1,1) = 0.7094 0.2760 0.6551 0.7547 0.6797 0.1626 x(:,:,2,1) = 0.1190 0.9597 0.5853 0.4984 0.3404 0.2238 x(:,:,3,1) = 0.7513 0.5060 0.8909 0.2551 0.6991 0.9593 x(:,:,4,1) = 0.5472 0.1493 0.8407 0.1386 0.2575 0.2543 x(:,:,1,2) = 0.8143 0.9293 0.1966 0.2435 0.3500 0.2511 x(:,:,2,2) = 0.6160 0.3517 0.5853 0.4733 0.8308 0.5497 x(:,:,3,2) = 0.9172 0.7572 0.3804 0.2858 0.7537 0.5678 x(:,:,4,2) = 0.0759 0.5308 0.9340 0.0540 0.7792 0.1299 x(:,:,1,3) = 0.5688 0.0119 0.1622 0.4694 0.3371 0.7943 x(:,:,2,3) = 0.3112 0.1656 0.2630 0.5285 0.6020 0.6541 x(:,:,3,3) = 0.6892 0.4505 0.2290 0.7482 0.0838 0.9133 x(:,:,4,3) = 0.1524 0.5383 0.0782 0.8258 0.9961 0.4427 x(:,:,1,4) = 0.1067 0.0046 0.8173 0.9619 0.7749 0.8687 x(:,:,2,4) = 0.0844 0.2599 0.4314 0.3998 0.8001 0.9106 x(:,:,3,4) = 0.1818 0.1455 0.8693 0.2638 0.1361 0.5797 x(:,:,4,4) = 0.5499 0.8530 0.3510 0.1450 0.6221 0.5132 x(:,:,1,5) = 0.4018 0.2399 0.1839 0.0760 0.1233 0.2400 x(:,:,2,5) = 0.4173 0.9027 0.4909 0.0497 0.9448 0.4893 x(:,:,3,5) = 0.3377 0.3692 0.7803 0.9001 0.1112 0.3897 x(:,:,4,5) = 0.2417 0.0965 0.9421 0.4039 0.1320 0.9561 ```