I am having trouble trying to make this work. I want it so that whenever a value in t is 1, it will output five zeros onto a row vector. Whenever the value of t is 2, I want it to output 5 ones to the same row vector. When the value of t is 3, I want it to output 5 twos onto the row vector. I want it so that my ending vector will be [0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 2 2 2 2 2]. Right now, it is only showing [0 1 0 1 0 2], so basically it is only outputting the value that I want once. How can I make it output the same number that I want 5 times instead of just once?
t = [1, 2, 1, 2, 1, 3];d = 0;for n = 1:length(t) if (t(n) == 1) for k = 0:4 k = k+1; d(n) = 0; end elseif (t(n) == 2) for k = 0:4 k = k+1; d(n) = 1; end elseif (t(n) == 3) for k = 0:4 k = k+1; d(n) = 2; end endenddisplay(d)
Best Answer