How do I plot multiple names and rankings and find them?
4 views (last 30 days)
Show older comments
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
Answers (1)
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)))];
0 Comments
See Also
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!