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

Example:

Input

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

Output

    vector = [0 1 0 0 0 0]

Solution Stats

820 Solutions

533 Solvers

Last Solution submitted on Jan 23, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers533

Suggested Problems

More from this Author56

Problem Tags

Community Treasure Hunt

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

Start Hunting!