Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function Name: trackList Inputs 1. (char) A 1x(6*N) vector of song names 2. (log

ID: 3748479 • Letter: F

Question

Function Name: trackList Inputs 1. (char) A 1x(6*N) vector of song names 2. (logical) A 1xN vector of whether or not each song is on that artist's tracklist Outputs 1. (char) A 1xP vector of the song names that should not be on the tracklist 2. (double) A 1xM vector of the original positions of the actual songs Background Music Midtown 2018 is coming up and you're really excited to go! The lineup of all the artists performing was just released and to prepare for the festival you're going to go through and listen to some of the artists' music. But Spotify just got hacked and now the tracklists of different albums have the wrong songs in them! You decide to use MATLAB to figure out which songs in the tracklist were actually sung by the artist. Function Description: Given a list of the first 5 letters of the songs in a mixed up tracklist and a logical vector of whether the song belongs in the tracklist, output the songs that should not be included in the tracklist. You should also output a vector of the positions of the songs that belong in ascending order Example The following gives an example of the two outputs for the following test case >> songsFLASH HOMEC >> belong - [true true false false true true] >> [wrong, positions]-trackList(songs, belong) TT STRON wrong -MASKO DESPA' positions [1 2 561 Notes: . Song names will always be five capital letters followed by a space, both in the input and output. . You will not be given a test case with no falses in the logical input vector

Explanation / Answer

Matlab Code:

function [wrong, positions] = trackList(songs, belong)

                count = 0;

                wrong = "";

                positions = [];

                for i = 1 : length(belong)

                                if ~belong(i)

                                                remove = songs((i-1)*6+1 - count*6: (i-1)*6+1 - count*6 + 5);

                                                wrong = [wrong, '', remove];

                                                songs((i-1)*6+1 - count*6: (i-1)*6+1 - count*6 + 5)=[];

                                                count += 1;

                                else

                                                positions = [positions i];

                                end

                end

end

songs = 'FLASH HOMEC MASKO DESPA CANTT STRON ';

belong = [true true false false true true];

[wrong, positions] = trackList(songs, belong)