Your example only includes lower case so this code does as well.
function randLetters = myfunc(integer)
letters = 'a' : 'z';
rnum = randi(length(letters), 1, abs(integer));
randLetters = cell(1, abs(integer));
for i = 1:abs(integer)
randLetters{i} = letters(rnum(1:i));
end
if integer < 0
randLetters = fliplr(randLetters);
end
Example
myfunc(8)
ans =
1×8 cell array
{'r'} {'rw'} {'rwf'} {'rwfh'} {'rwfht'} {'rwfhtb'} {'rwfhtbt'} {'rwfhtbta'}
myfunc(-4)
ans =
1×4 cell array
{'whke'} {'whk'} {'wh'} {'w'}
Best Answer