MATLAB: How to repeat a character n times

charconcatenatehistogramrepeatrepmat

Freq=[s0,s1,s2,s3,s4,s5,s6,s7,s8,s9];
hist=[1,length(Freq)];
for k=1:length(Freq)
hist(k)=repmat('*',Freq(k));
end
I want to create a row vector where every element in 'hist' has '*' whose quantity corresponds to the elements from the array 'Freq'. If Freq(5)=6 then hist(5) = '******'

Best Answer

Because your histogram counts will result in variable length strings of asterisks, you'll need to use cell arrays to store each string.
Freq=[s0,s1,s2,s3,s4,s5,s6,s7,s8,s9];
hist=cell(1,length(Freq));
for k=1:length(Freq)
hist{k}=repmat('*',1,Freq(k));
end
Access the k-th string using hist{k} (note the curly braces).