Cody

Problem 410. Back to basics 20 - singleton dimensions

Solution 460657

Submitted on 23 Jun 2014 by Abdullah Caliskan
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))

r = 2 3 1 4 ans(:,:,1) = 0.4274 0.8798 0.5164 0.6021 0.6814 0.3315 ans(:,:,2) = 0.7370 0.1594 0.5159 0.1303 0.7451 0.6602 ans(:,:,3) = 0.1587 0.8698 0.1013 0.2137 0.8562 0.4330 ans(:,:,4) = 0.2496 0.5257 0.8262 0.5576 0.4101 0.3967

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

r = 2 3 4 ans(:,:,1) = 0.1011 0.2004 0.2067 0.0346 0.3390 0.3343 ans(:,:,2) = 0.8273 0.4240 0.7738 0.4283 0.3929 0.2025 ans(:,:,3) = 0.6785 0.8408 0.0134 0.7176 0.6916 0.6534 ans(:,:,4) = 0.8458 0.5128 0.3552 0.7373 0.2332 0.3307

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

r = 1 2 3 4 5 ans(:,:,1,1) = 0.0540 0.9793 0.4984 0.2850 0.3432 0.9727 ans(:,:,2,1) = 0.9264 0.0813 0.1328 0.5624 0.5720 0.4770 ans(:,:,3,1) = 0.7170 0.7299 0.5984 0.1376 0.5270 0.8006 ans(:,:,4,1) = 0.5919 0.8838 0.4298 0.0948 0.7440 0.3775 ans(:,:,1,2) = 0.0762 0.1477 0.6211 0.8967 0.8427 0.1654 ans(:,:,2,2) = 0.3420 0.9060 0.2537 0.7792 0.9875 0.4824 ans(:,:,3,2) = 0.7835 0.4271 0.1914 0.4110 0.3227 0.9227 ans(:,:,4,2) = 0.5626 0.6376 0.2189 0.2114 0.6751 0.8096 ans(:,:,1,3) = 0.9324 0.8100 0.3706 0.2002 0.1407 0.6795 ans(:,:,2,3) = 0.8397 0.9643 0.6373 0.3897 0.6942 0.7925 ans(:,:,3,3) = 0.6715 0.9872 0.1112 0.5984 0.5571 0.2281 ans(:,:,4,3) = 0.5661 0.8949 0.3229 0.3760 0.1605 0.7960 ans(:,:,1,4) = 0.4364 0.3112 0.4463 0.0513 0.2133 0.3071 ans(:,:,2,4) = 0.9948 0.1358 0.9357 0.3716 0.7220 0.9859 ans(:,:,3,4) = 0.1796 0.4012 0.9115 0.5496 0.0560 0.5737 ans(:,:,4,4) = 0.1701 0.4917 0.4277 0.6367 0.3337 0.3467 ans(:,:,1,5) = 0.4272 0.0128 0.5709 0.3838 0.1218 0.3492 ans(:,:,2,5) = 0.0819 0.2705 0.0506 0.7951 0.8114 0.2133 ans(:,:,3,5) = 0.9463 0.0725 0.3242 0.8403 0.0901 0.7342 ans(:,:,4,5) = 0.9870 0.6110 0.7926 0.2141 0.7125 0.9703

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!