Problem 1065. Make a 1 hot vector

Make a vector of length N that consists of all zeros except at index k, where it has the value 1.



    N = 6;
    k = 2;
    vector = one_hot(N,k);


    vector = [0 1 0 0 0 0]

Solution Stats

80.66% Correct | 19.34% Incorrect
Last solution submitted on Dec 05, 2016

Problem Comments


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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more