How do I plot multiple names and rankings and find them?

4 views (last 30 days)
So i have the user input the baby names (min 5 max 7) then I save the baby name and make sure the first letter is capitalize then I find the baby name in my baby name file. From there how do I also find the ranking and plot? I am so lost on how to use strings and such here is my code
% Display a menu and get a choice
choice = menu('Choose an option','Exit Program','Load Data File','Plot Family Graph');
% as you develop functions, add buttons for the here
while choice ~= 1
switch choice
case 0
disp('Error - please choose one of the options.')
% Display a menu and get a choice
choice = menu('Choose an option','Exit Program','Load Data File','Plot Family Graph');
case 1
%exit
case 2
% Load into one baby name and one ranking by using the function
[names, rankings] = Read_names_file();
if isempty(names)
return
else
disp('Data loaded.')
end
%open menu options again
choice = menu('Choose an option','Exit Program','Load Data File','Plot Family Graph');
case 3
%plot family graph
numberNames = input('Type in the number of names you want to research (min 5, max 7):');
if numberNames > 7 || numberNames < 5;
fprintf('Invalid number try again \n')
numberNames = input('Type in the number of names you want to research (min 5, max 7):');
else
for i = 1:numberNames;
babyName = input('Please enter a baby name: ','s');
babyName = [upper(strcat(babyName(1))) lower(strcat(babyName(2:end)))];
end
end
fprintf('%s \n', babyName);
%ind = find(ismember(names, babyName));
%babyPlot = strcmp(names, babyName);
x = strmatch(babyName, names);
if isempty(x)
disp('empty')
end
y = strfind(babyName,rankings , 'extract');
if isempty(y)
disp('empty')
end
figure
plot(x,y)
end
choice = menu('Choose an option','Exit Program','Load Data File','Plot Family Graph');
end
  2 Comments
Sarah Huynh
Sarah Huynh on 24 Jul 2015
i'm sorry, i'm trying to make a graph that plots info from my file. in that file contains baby names and their rankings.
In general I have made a menu to give the user the options to load my file
then after the file is loaded i then give the user an option to plot the graph
after that I ask how many names do they wish to see on the graph
problem:
I do not know how to ask the user to give me the names and save it into different variables.
I only am able to save one name,
after that I do not know how to find the name they have inputed to find the names on my loaded file to plot the graph.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 24 Jul 2015
babyName{i} = input('Please enter a baby name: ','s');
babyName{i} = [upper(strcat(babyName{i}(1))) lower(strcat(babyName{i}(2:end)))];

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!