Cody

# Problem 410. Back to basics 20 - singleton dimensions

Solution 71901

Submitted on 6 Apr 2012 by Bruce Raine
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))

y(:,:,1) = 0.5617 0.2036 0.0244 0.0761 0.0116 0.9964 y(:,:,2) = 0.8643 0.5964 0.4285 0.1475 0.6215 0.3230 y(:,:,3) = 0.7821 0.2749 0.8741 0.0717 0.0708 0.3252 y(:,:,4) = 0.0544 0.9567 0.6194 0.6991 0.7073 0.6386

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

y(:,:,1) = 0.8807 0.0080 0.3242 0.2459 0.4927 0.1586 y(:,:,2) = 0.0263 0.8450 0.7328 0.6522 0.4537 0.5756 y(:,:,3) = 0.0870 0.8468 0.2924 0.8294 0.4174 0.7824 y(:,:,4) = 0.5194 0.9175 0.7735 0.4777 0.1773 0.0405

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

y(:,:,1,1) = 0.4066 0.8958 0.2370 0.9994 0.6646 0.8242 y(:,:,2,1) = 0.9897 0.3968 0.5543 0.5335 0.2263 0.1615 y(:,:,3,1) = 0.0409 0.0940 0.3421 0.1381 0.3036 0.0800 y(:,:,4,1) = 0.1630 0.8184 0.5685 0.2984 0.4740 0.7820 y(:,:,1,2) = 0.7165 0.0558 0.7534 0.4526 0.1259 0.3769 y(:,:,2,2) = 0.5663 0.9950 0.5041 0.2103 0.5125 0.1254 y(:,:,3,2) = 0.9863 0.7399 0.4230 0.3271 0.1077 0.1658 y(:,:,4,2) = 0.1401 0.8146 0.3959 0.9428 0.4919 0.8290 y(:,:,1,3) = 0.2836 0.3561 0.5031 0.5424 0.4600 0.0688 y(:,:,2,3) = 0.9577 0.7035 0.1283 0.1570 0.7886 0.8703 y(:,:,3,3) = 0.5867 0.0953 0.4394 0.7847 0.6001 0.1317 y(:,:,4,3) = 0.8610 0.4587 0.3089 0.5487 0.9598 0.8346 y(:,:,1,4) = 0.4733 0.4885 0.8569 0.3201 0.2119 0.9706 y(:,:,2,4) = 0.6899 0.3809 0.1322 0.5246 0.6078 0.1490 y(:,:,3,4) = 0.3411 0.5458 0.6879 0.1253 0.3903 0.9521 y(:,:,4,4) = 0.0217 0.0726 0.2690 0.4149 0.9393 0.7957 y(:,:,1,5) = 0.7991 0.0659 0.3698 0.9161 0.2456 0.4827 y(:,:,2,5) = 0.8635 0.1579 0.4285 0.5156 0.1428 0.9706 y(:,:,3,5) = 0.8294 0.6750 0.2171 0.6962 0.7143 0.2513 y(:,:,4,5) = 0.2953 0.2582 0.8263 0.7998 0.2389 0.2969

### Community Treasure Hunt

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

Start Hunting!