MATLAB: Random choice of elements for n times, without choosing the same element more than once

random choise

Hello! I am trying to randomly choose one element from a string for a predifined number of times but I don't know how I can avoid getting the same element more than once.. Beneath is the code I wrote (my question may be more comprehensible through the comment in the code).
%% ************************************ *******************************************
letters = 'ABCD';
ntrials = 3;
nletters = 4;
for i = 2: ntrials
for j = 1: nletters
*% it needs to display a random letter from letters but the same
% letter must NOT appear more than once in this nested loop.*
end
end
% ******************************* end of code ************************************************
output example: BCAD ADCB
Thanks a lot!

Best Answer

Perhaps you mean:
for i = 2: ntrials
C = letters(randperm(length(letters), nletters))
end
Do you want to store the different outputs?