Need the proper MATLAB code for this one. The output text file is above the func
ID: 3723811 • Letter: N
Question
Need the proper MATLAB code for this one. The output text file is above the function description and the solution file is below the description. The output text file should be called '_review.txt'. Read the instructions plz I am having so much trouble with this. I have already put the output file in the text above.
So the album image text file I posted above is called 'Divide.txt'
The output file with the description should be called 'Divide_review.txt' and should have three lines, ONLY THREE LINES. The text should say:
Review of Divide's album art:
The cover has a darkness score of 4.99.
Cover of medium darkness, seems like it could be a bit too edgy...
!!22222!nnnnu @g@@* @g@@@g@@ @@0 ****n@000@@@0? * * @0@@@@! !!*Explanation / Answer
We iterate over all the characters and find the score for each, which is basically the index in the scores array. If we do not find the character in the scores array (like for newline characters in the album art), we simply move to the next character.
function albumArt(fileName)
scores = '@%?!*~. ';
fin = fopen(fileName, 'r');
[A, char_count] = fscanf(fin, '%c');
nz_count = 0;
total = 0;
for i = 1:char_count
score = find(scores == A(i));
if(score)
total = total + score;
nz_count = nz_count + 1;
else
continue;
end
end
mean = total / nz_count;
review = '';
if(mean > 5)
review = 'Very light cover, probably good music for kids! ';
elseif (mean > 3)
review = 'Cover of medium darkness, seems like it could be a bit too edgy... ';
else
review = 'Cover is very dark, looks like something quite inappropriate for children. ';
end
[filepath, base, ext] = fileparts(fileName);
fout = fopen([base, '_review.txt'], 'w');
fprintf(fout, 'Review of %ss album art: ', base);
fprintf(fout, 'The cover has a darkness score of %f ', mean);
fprintf(fout, review);
fclose(fout);
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.