Question
Inputs: (char) 1x4N character vector of 'Yea' and 'Nay' (double) 1xN vector of volunteer IDs (double) The number of volunteers needed Outputs: 1. (double) 1xM
Inputs:
-
(char) 1x4N character vector of 'Yea' and 'Nay'
-
(double) 1xN vector of volunteer IDs
-
(double) The number of volunteers needed
Outputs:
1. (double) 1xM vector of IDs who were selected
Background:
You are running the volunteer pool for the Olympic Marathon Tryouts. Unfortunately, your bosses have declined to give you any resources to organize the multitudes of volunteers required for this event. Fortunately, you don't need any resources other than MATLAB!
Function Description:
You are given a character vector consisting of the words 'Yea' and 'Nay' separated by spaces where the first word represents the first volunteer's answer, the second represents the second volunteers answer, and so on. First find all those who answered 'Yea'. Then select the number of volunteers given by the third input from the front of those who answered 'Yea'.
Example:
answers = 'Yea Nay Yea Yea Nay '; volunteers = [21, 5, 31, 10, 2]; needed = 2; selected = yeaOrNay(answers, volunteers, needed); selected [21 31]
Notes:
-
There will always be enough 'Yea' answers to fill all selected spots.
-
The string will always follow this capitalization pattern.
-
There will only be one space separating words and one trailing space after the last word.
Hints:
-
Think of how you can reduce the number of characters in the first input without reducing the amount of information contained.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started