Cody

Problem 410. Back to basics 20 - singleton dimensions

Solution 302437

Submitted on 12 Aug 2013 by Jan Orwat
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.0975 0.5469 0.9649 0.2785 0.9575 0.1576 ans(:,:,2) = 0.9706 0.4854 0.1419 0.9572 0.8003 0.4218 ans(:,:,3) = 0.9157 0.9595 0.0357 0.7922 0.6557 0.8491 ans(:,:,4) = 0.9340 0.7577 0.3922 0.6787 0.7431 0.6555

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

ans(:,:,1) = 0.1712 0.0318 0.0462 0.7060 0.2769 0.0971 ans(:,:,2) = 0.8235 0.3171 0.0344 0.6948 0.9502 0.4387 ans(:,:,3) = 0.3816 0.7952 0.4898 0.7655 0.1869 0.4456 ans(:,:,4) = 0.6463 0.7547 0.6797 0.7094 0.2760 0.6551

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

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

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!