Cody

# Problem 410. Back to basics 20 - singleton dimensions

Solution 713103

Submitted on 11 Aug 2015 by Peng Liu
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.8653 0.8802 0.2914 0.9500 0.3952 0.1290 ans(:,:,2) = 0.9279 0.0333 0.2526 0.6330 0.1304 0.8734 ans(:,:,3) = 0.7160 0.5994 0.9799 0.7631 0.2600 0.9618 ans(:,:,4) = 0.8697 0.6868 0.0392 0.5383 0.1315 0.9996

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

ans(:,:,1) = 0.8965 0.9908 0.3857 0.0115 0.8144 0.0520 ans(:,:,2) = 0.6656 0.7727 0.5505 0.0893 0.7849 0.0087 ans(:,:,3) = 0.8586 0.8520 0.6461 0.2946 0.3967 0.3553 ans(:,:,4) = 0.6125 0.7447 0.2597 0.8398 0.6781 0.3386

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

ans(:,:,1,1) = 0.4254 0.8878 0.3485 0.4086 0.4708 0.4980 ans(:,:,2,1) = 0.7497 0.1210 0.5135 0.4349 0.3362 0.1629 ans(:,:,3,1) = 0.2941 0.7387 0.4261 0.3451 0.1527 0.4462 ans(:,:,4,1) = 0.1294 0.2088 0.5879 0.6773 0.8595 0.1479 ans(:,:,1,2) = 0.9512 0.3653 0.3467 0.5428 0.7387 0.8704 ans(:,:,2,2) = 0.7546 0.9521 0.5882 0.4447 0.4630 0.2120 ans(:,:,3,2) = 0.0912 0.3161 0.8152 0.7262 0.9270 0.0777 ans(:,:,4,2) = 0.7442 0.7167 0.1060 0.4638 0.2192 0.7897 ans(:,:,1,3) = 0.6553 0.4222 0.3640 0.6270 0.0171 0.2433 ans(:,:,2,3) = 0.6395 0.1756 0.2450 0.4296 0.7828 0.8513 ans(:,:,3,3) = 0.2577 0.3507 0.8404 0.2988 0.5247 0.6623 ans(:,:,4,3) = 0.6545 0.0426 0.2661 0.8008 0.5703 0.6283 ans(:,:,1,4) = 0.1357 0.5986 0.1426 0.4487 0.8785 0.7360 ans(:,:,2,4) = 0.7424 0.9018 0.4253 0.4722 0.7748 0.6883 ans(:,:,3,4) = 0.3127 0.0730 0.0414 0.6840 0.3239 0.1758 ans(:,:,4,4) = 0.9093 0.7056 0.1969 0.3307 0.8410 0.6768 ans(:,:,1,5) = 0.1770 0.7156 0.4141 0.4880 0.1984 0.5955 ans(:,:,2,5) = 0.9989 0.0812 0.9232 0.0074 0.0386 0.4274 ans(:,:,3,5) = 0.7999 0.6127 0.5423 0.3306 0.5687 0.2224 ans(:,:,4,5) = 0.0022 0.3068 0.1721 0.8541 0.5345 0.4898

### Community Treasure Hunt

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

Start Hunting!