Cody

Problem 410. Back to basics 20 - singleton dimensions

Solution 860416

Submitted on 1 Apr 2016 by HH
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.0617 0.2645 0.6344 0.5134 0.0667 0.7584 x(:,:,2) = 0.5027 0.8587 0.5555 0.1354 0.4591 0.8471 x(:,:,3) = 0.8231 0.4206 0.3286 0.1790 0.9971 0.4436 x(:,:,4) = 0.9014 0.7627 0.3663 0.1761 0.3015 0.3558

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

x(:,:,1) = 0.9580 0.3709 0.1219 0.1620 0.3890 0.0204 x(:,:,2) = 0.6848 0.4849 0.3130 0.7963 0.9457 0.8680 x(:,:,3) = 0.0715 0.9804 0.4090 0.0312 0.5255 0.5203 x(:,:,4) = 0.4689 0.8756 0.5615 0.3636 0.0391 0.9282

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

x(:,:,1,1) = 0.2077 0.5460 0.0981 0.0031 0.8609 0.8079 x(:,:,2,1) = 0.1577 0.1343 0.4293 0.3199 0.0093 0.0271 x(:,:,3,1) = 0.3605 0.0085 0.9236 0.3632 0.4066 0.6977 x(:,:,4,1) = 0.1209 0.2389 0.9332 0.0444 0.4635 0.3839 x(:,:,1,2) = 0.7118 0.9513 0.8287 0.1444 0.1458 0.3705 x(:,:,2,2) = 0.0686 0.7791 0.2714 0.2543 0.3731 0.1655 x(:,:,3,2) = 0.8418 0.1709 0.6402 0.6070 0.0145 0.3252 x(:,:,4,2) = 0.8796 0.7111 0.4595 0.1066 0.2214 0.3029 x(:,:,1,3) = 0.8500 0.6957 0.1494 0.9846 0.3011 0.1036 x(:,:,2,3) = 0.4975 0.6617 0.6911 0.4233 0.5321 0.6209 x(:,:,3,3) = 0.1869 0.5814 0.6512 0.4977 0.0457 0.4746 x(:,:,4,3) = 0.2095 0.1965 0.6806 0.5247 0.2609 0.5419 x(:,:,1,4) = 0.0870 0.8837 0.3054 0.9391 0.8788 0.1356 x(:,:,2,4) = 0.8624 0.7893 0.2890 0.6556 0.8958 0.9512 x(:,:,3,4) = 0.4527 0.8846 0.7281 0.7142 0.2612 0.5646 x(:,:,4,4) = 0.2449 0.5805 0.1946 0.4121 0.0346 0.2542 x(:,:,1,5) = 0.9598 0.0334 0.4787 0.0663 0.2359 0.0445 x(:,:,2,5) = 0.1459 0.3550 0.0119 0.0468 0.7342 0.2271 x(:,:,3,5) = 0.1332 0.6114 0.0661 0.7594 0.4385 0.3187 x(:,:,4,5) = 0.9637 0.4999 0.8022 0.6192 0.4266 0.4626

Suggested Problems

More from this Author39

Community Treasure Hunt

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

Start Hunting!