MATLAB: Indexing for a character vector and referring to them in a while loop

indexing

Is it possible to have a set of data under a while loop and add them to a vector of matrices and then refer back to that same vector? For example, the user enters a set of data into a program whilst its under a while loop with an if statement and the program then refers back to that same data under a different if statement? The program below allows to list people but is it possible to add the people listed to a character vector and refer back to it when you have count them or pick one of them out. I could add 3 people of different ages and names and then count how many of them are added.
while prompt >=' '
prompt=input('\nWhat would you like to do: ', 's');
if strcmp(prompt,'list people')
name=input('Name: ', 's');
gender=input('Gender: ', 's');
age=input('Age: ', 's');
elseif strcmp(prompt, 'count people')
end
end

Best Answer

k = 0;
S = struct();
str = 'X';
while ~isempty(str)
str = input('What would you like to do: ', 's');
switch lower(str)
case 'list'
k = k+1;
S(k).name = input('Name: ', 's');
S(k).gender = input('Gender: ', 's');
S(k).age = input('Age: ', 's');
case 'count'
disp(k)
end
end
And tested:
>>
What would you like to do: list
Name: anna
Gender: F
Age: 31
What would you like to do: list
Name: bob
Gender: M
Age: 64
What would you like to do: count
2
What would you like to do:
>>