MATLAB: Problem with storing data into cell aray

cell array

Hello,
I am very new to matlab and I have run into a problem with cell arrays. My homework was to create a classic guess-a-number-game with a limited amount of rounds and trials within the round. I want to store the guesses for each round in a vector and append it to the cell array at the end of the round. However, my cell array doesn't show me the actual elements (like vectors with guesses) but looks like this: all_guesses =
[1x5 double] [1x5 double] [10]
Here's my code:
rounds = 3;
maxtrials = 5;
guess_history = [] %to create a vector
all_guesses = {} % cell array with the history of guesses for all three rounds
for r = 1:rounds %loop for three rounds
fprintf('\n Welcome to "Guess the Number"');
fprintf('\n This is round number: (%i). ',r);
secret = randi(10)
trial = 0;
while true
trial = trial +1;
if trial > maxtrials %check
fprintf('Maximum number of trials reached!\n \n')
break;
guess = input('have a guess: ');
guess_history(trial) = guess
if guess == secret %the actual game
fprintf ('you are right, it is %i\n', guess)
break %it breaks the while loop
elseif guess < secret
fprintf ('%i is too low\n ', guess)
else
fprintf ('%i is too high\n', guess)
end;
end;
all_guesses{r} = guess_history
clear guess_history
end;
save /path/guesses.m all_guesses
I also tried to store it like this: all_guesses{r, trial} = guess after the guess is being done, but it just creates a weird matrix.
Do you have any idea of what might be wrong here? Thanks!

Best Answer

There is nothing wrong. That is how MATLAB displays cell contents if the cell contents are not a simple scalar array or a short string, in which case it prints the size and class of the variable in the cell:
>> C = {1,[3,4]}
C =
[1] [1x2 double]
The content of the cell are still there:
>> C{2}
ans =
3 4
Instead of relying on printing data to your command window, you should try using the Variable Editor: simply double click on a variable in your workspace panel to open it in the Variable Editor. The Variable Editor lets you click through all levels of cell arrays and structures too, so you can view all of the data.