MATLAB: How does one store all the words from a loop into a variable

for loopssaving values

for j = 1:length(wordsB)
PositionB = Shuffle2 (j); % Use number from the random array
% wordsB (PositionB); % Assign random position to words in text file
RandomWordsB = wordsB(PositionB);
% RandomWordsB = wordsB(PositionB); %Assign the obtained list to a varible to be displayed
disp (RandomWordsB) %display the random word list
end
RandomWords = [RandomWordsA; RandomWordsB]; %combining words from both arrays
disp (RandomWords) %display the random word lists

Best Answer

You can store them as cells like below:
RandomWordsA=cell(1,numel(wordsA));
for i = 1:length(wordsA)
PositionA = Shuffle1 (i); % Use number from the random array
% wordsA (PositionA); % Assign random position to words in text file
RandomWordsA{i} = wordsA(PositionA); %Assign the obtained list to a varible to be displayed
disp (RandomWordsA) %display the random word list
end
celldisp(RandomWordsA)