Cody

Problem 410. Back to basics 20 - singleton dimensions

Solution 372553

Submitted on 19 Dec 2013 by Robert
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))

s = Type: 'Legacy' Seed: 'Not applicable' State: {[2x1 uint32] [750718567] [35x1 double] [625x1 uint32] [2.0952e+09] [2x1 double]} a = 2 3 1 4 a = 2 3 4 y(:,:,1) = 0.1849 0.3667 0.7938 0.5690 0.2709 0.1277 y(:,:,2) = 0.4710 0.7758 0.4747 0.2936 0.8950 0.8183 y(:,:,3) = 0.0385 0.1436 0.5468 0.6831 0.0219 0.4011 y(:,:,4) = 0.0863 0.6528 0.5602 0.8791 0.5731 0.6689

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

s = Type: 'Legacy' Seed: 'Not applicable' State: {[2x1 uint32] [1.4903e+09] [35x1 double] [625x1 uint32] [2.0952e+09] [2x1 double]} a = 2 3 4 a = 2 3 4 y(:,:,1) = 0.1406 0.6975 0.0541 0.6990 0.3610 0.5656 y(:,:,2) = 0.9446 0.7033 0.7234 0.3132 0.0852 0.8449 y(:,:,3) = 0.0350 0.3711 0.0554 0.9390 0.1439 0.4746 y(:,:,4) = 0.8556 0.0028 0.7852 0.5181 0.6981 0.8379

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

s = Type: 'Legacy' Seed: 'Not applicable' State: {[2x1 uint32] [45717127] [35x1 double] [625x1 uint32] [2.0952e+09] [2x1 double]} a = 1 2 3 4 5 a = 2 3 4 5 y(:,:,1,1) = 0.2077 0.0622 0.0365 0.5219 0.8554 0.6286 y(:,:,2,1) = 0.1369 0.1357 0.0282 0.5221 0.4326 0.6011 y(:,:,3,1) = 0.0252 0.1999 0.2973 0.7132 0.0136 0.1678 y(:,:,4,1) = 0.4875 0.0290 0.3299 0.6630 0.3132 0.7026 y(:,:,1,2) = 0.3458 0.5074 0.9348 0.4611 0.7620 0.2846 y(:,:,2,2) = 0.4428 0.5276 0.3729 0.6305 0.8137 0.9496 y(:,:,3,2) = 0.2840 0.7753 0.4818 0.5183 0.2226 0.5644 y(:,:,4,2) = 0.5998 0.2930 0.5664 0.8377 0.2908 0.2278 y(:,:,1,3) = 0.8812 0.9143 0.8633 0.5060 0.4559 0.2123 y(:,:,2,3) = 0.9091 0.6341 0.6643 0.1805 0.4828 0.9077 y(:,:,3,3) = 0.1730 0.0261 0.1509 0.3422 0.1495 0.4377 y(:,:,4,3) = 0.2610 0.2955 0.8899 0.2268 0.2529 0.6171 y(:,:,1,4) = 0.6673 0.7855 0.9133 0.1756 0.4544 0.9783 y(:,:,2,4) = 0.7002 0.9834 0.0153 0.7857 0.6396 0.5279 y(:,:,3,4) = 0.5925 0.4957 0.3306 0.7980 0.3233 0.4508 y(:,:,4,4) = 0.5088 0.9723 0.8832 0.1439 0.8587 0.2402 y(:,:,1,5) = 0.3424 0.6418 0.4055 0.5411 0.0833 0.0164 y(:,:,2,5) = 0.6866 0.9138 0.2753 0.0994 0.5899 0.0983 y(:,:,3,5) = 0.8836 0.9322 0.3713 0.5389 0.6633 0.4242 y(:,:,4,5) = 0.8308 0.5922 0.2718 0.5553 0.5865 0.2729

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!