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 171277

Submitted on 1 Dec 2012 by Suresh Deoda

Correct

20Size
Leading solution size is 11.
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
 
%%
assert(isequal(one_hot(1,1),1))

                    
2
Pass
 
%%
assert(isequal(one_hot(2,1),[1 0]))

                    
3
Pass
 
%%
assert(isequal(one_hot(3,3),[0 0 1]))

                    
4
Pass
 
%%
assert(isequal(one_hot(4,1),[1 0 0 0]))

                    
5
Pass
 
%%
assert(isequal(one_hot(5,2),[0 1 0 0 0]))

                    
6
Pass
 
%%
assert(isequal(one_hot(6,1),[1 0 0 0 0 0]))

                    
7
Pass
 
%%
assert(isequal(one_hot(7,1),[1 0 0 0 0 0 0]))

                    
8
Pass
 
%%
assert(isequal(one_hot(8,7),[0 0 0 0 0 0 1 0]))

                    
9
Pass
 
%%
assert(isequal(one_hot(9,7),[0 0 0 0 0 0 1 0 0]))

                    
10
Pass
 
%%
assert(isequal(one_hot(10,4),[0 0 0 1 0 0 0 0 0 0]))

                    
11
Pass
 
%%
assert(isequal(one_hot(11,11),[0 0 0 0 0 0 0 0 0 0 1]))

                    
12
Pass
 
%%
assert(isequal(one_hot(12,1),[1 0 0 0 0 0 0 0 0 0 0 0]))

                    
13
Pass
 
%%
assert(isequal(one_hot(13,6),[0 0 0 0 0 1 0 0 0 0 0 0 0]))

                    
14
Pass
 
%%
assert(isequal(one_hot(14,6),[0 0 0 0 0 1 0 0 0 0 0 0 0 0]))

                    
15
Pass
 
%%
assert(isequal(one_hot(15,12),[0 0 0 0 0 0 0 0 0 0 0 1 0 0 0]))

                    
16
Pass
 
%%
assert(isequal(one_hot(16,13),[0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0]))

                    
17
Pass
 
%%
assert(isequal(one_hot(17,4),[0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]))

                    
18
Pass
 
%%
assert(isequal(one_hot(18,9),[0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]))

                    
19
Pass
 
%%
assert(isequal(one_hot(19,9),[0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0]))

                    
20
Pass
 
%%
assert(isequal(one_hot(20,13),[0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]))