MATLAB: Random vector containing zero and values

MATLAB

I have an problem: I have a vector A with size N; I want to fill it up with a random vector with values from [1 randi(N)] while the other elements of A be zero. for example:
N = 6;
A(1:6)=0;
b = randi(N);
C =randperm(b);
now without any loop assign each element of C to the random positions of A while the other un-assigned elements of A remain zero if b<N;

Best Answer

a = zeros(1,6);
n = 6;
b = randi(n);
c = 1:b;
a( randperm( numel(a), b ) ) = c;