Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 185946

Submitted on 4 Jan 2013 by Tomasz

Correct

10Size
Leading solution size is 10.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
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.1546    0.2864    0.6022
    0.7227    0.5384    0.5334
ans(:,:,2) =
    0.1364    0.9494    0.6836
    0.3189    0.1499    0.5853
ans(:,:,3) =
    0.6598    0.1138    0.1901
    0.6388    0.5649    0.6285
ans(:,:,4) =
    0.8236    0.4021    0.5617
    0.1111    0.4951    0.8542
2
Pass
 
%%
x = rand(2,3,4);
y_correct = 3;
assert(isequal(ndims(remove_dims(x)),y_correct))
ans(:,:,1) =
    0.4839    0.0726    0.8255
    0.7883    0.8111    0.5793
ans(:,:,2) =
    0.9849    0.4512    0.6896
    0.7004    0.0611    0.2780
ans(:,:,3) =
    0.9504    0.9274    0.0699
    0.4254    0.1752    0.5675
ans(:,:,4) =
    0.1841    0.1199    0.2466
    0.4327    0.7420    0.5077
3
Pass
 
%%
x = rand(1,2,3,4,5);
y_correct = 4;
assert(isequal(ndims(remove_dims(x)),y_correct))
ans(:,:,1,1) =
    0.3356    0.6146    0.7744
    0.1986    0.1904    0.3042
ans(:,:,2,1) =
    0.1507    0.1147    0.5292
    0.2669    0.7070    0.7538
ans(:,:,3,1) =
    0.4262    0.0236    0.2768
    0.6805    0.2416    0.4748
ans(:,:,4,1) =
    0.4095    0.0271    0.2904
    0.0283    0.5963    0.2766
ans(:,:,1,2) =
    0.1478    0.6189    0.6608
    0.8033    0.7484    0.2661
ans(:,:,2,2) =
    0.1928    0.4797    0.3195
    0.1807    0.9279    0.7013
ans(:,:,3,2) =
    0.4292    0.8016    0.9869
    0.8802    0.1141    0.3931
ans(:,:,4,2) =
    0.6259    0.6909    0.2188
    0.1750    0.4023    0.4131
ans(:,:,1,3) =
    0.3208    0.1495    0.3560
    0.7195    0.5603    0.1299
ans(:,:,2,3) =
    0.2640    0.6813    0.8439
    0.1970    0.6387    0.8772
ans(:,:,3,3) =
    0.6471    0.5168    0.7117
    0.8487    0.5469    0.1116
ans(:,:,4,3) =
    0.9681    0.4080    0.1183
    0.5288    0.5642    0.6190
ans(:,:,1,4) =
    0.3722    0.4157    0.3746
    0.7532    0.0090    0.8017
ans(:,:,2,4) =
    0.3936    0.9361    0.8217
    0.8459    0.5139    0.8699
ans(:,:,3,4) =
    0.7174    0.2858    0.2652
    0.4051    0.5672    0.8987
ans(:,:,4,4) =
    0.2186    0.8717    0.5735
    0.5416    0.1752    0.9872
ans(:,:,1,5) =
    0.6388    0.0170    0.2414
    0.6255    0.2053    0.3148
ans(:,:,2,5) =
    0.1980    0.4919    0.2940
    0.1373    0.3389    0.5095
ans(:,:,3,5) =
    0.5788    0.1079    0.2403
    0.2054    0.2922    0.0232
ans(:,:,4,5) =
    0.2070    0.5517    0.6761
    0.2126    0.8629    0.9502