Function Name: favoriteBand Inputs 1. 2. (double) An array of numbers representi
ID: 3748751 • Letter: F
Question
Function Name: favoriteBand Inputs 1. 2. (double) An array of numbers representing the schedule of performances for the day (double) A 1xM vector of when you are expecting rain Outputs 1. (char) A character vector describing when and where your favorite band is playing 2. (double) An array of numbers representing the updated schedule Background: You've finally made it to Music Midtown, and you are absolutely overwhelmed by the vast number of amazing performances that will be going on all day. How are you going to be able to decide which band is your top priority?? Oh we know, MATLAB! Function Description Based on the schedule input and the expected rain input, you will figure out when and where your favorite band is playing after taking the rain into account. In the first input, the rows represent the order of bands playing (ex: bands playing second are in row 2) and the columns represent the different stages (ex: bands playing on the first stage are in column 1). First, account for the rain by deleting the row (or rows) that corresponds to the act (or acts) during which it will rain. Then, find the stage and order that your favorite band is playing. Your favorite band will have the maximum value in the array. Finally, output a character vector describing when and where they are playing in the following format: "My favorite band is act playing on Stage ! Example: >> schedule[3 7 2; 6 1 9; 11 2 8; 8 5 3] >>rainTime3 >> [fave, sched]favoriteBand(schedule, rainTime) faveMy favorite band is act 2 playing on Stage 3!' sched [3 7 2; 6 1 9; 8 5 3] Notes: There is guaranteed to only be one top band; the greatest number in the array will be unique . . The second input can be either a scalar or a vector. Hints . You may find the second output of max() useful . Use %d with sprintf() for the stage and order numbersExplanation / Answer
Matlab Code:
function [fave, sched] = favoriteBand(schedule, rainTime)
count = 0;
for i = rainTime
schedule(i-count, :) = [];
count += 1;
end
sched = schedule;
[M,I] = max(schedule(:));
[row, col] = ind2sub(size(sched),I);
fave = sprintf("My favourite band is act %d playing on Stage %d!", row, col);
end
schedule = [3 7 2; 6 1 9; 11 2 8; 8 5 3];
rainTime = 3;
[fave, sched] = favoriteBand(schedule, rainTime)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.