Problem 1686. Generate a melodic contour string matrix
Parsons code is a surprisingly effective way to identify music by its melodic motion. That is, with each successive note, does the pitch go up, down, or stay the same. No effort is made to capture the length of the interval between notes. The result is a lossy but useful "thumbprint" of a musical piece.
You will be given a string in Parsons code. By convention, the first note is denoted by *. Each note thereafter is either "u" for up, "d" for down, or "r" for repeat. The expected output is a string matrix showing the tune's contour. It can contain only space, star, dash, forward slash, and backward slash (ASCII values 32, 42, 45, 47, and 92 respectively). The output matrix should be the smallest possible bounding box that can contain all the nonspace characters. That is, there should be no empty rows or columns.
Examples:
str = '*rrr' melody = '*-*-*-*'
str = '*du' melody = ['* *' ' \ / ' ' * ']
The "Happy Birthday" song! str = '*rududdrudud' melody = [' * * ' ' / \ / \ ' '*-* * * * * ' ' \ / \ / \ ' ' *-* * *']
Solution Stats
Problem Comments
-
5 Comments
There is an error in the second problem of the test suite (also in the example) with an extra "[" on the second line of the "correct" melody.
Amazing how hard it is to get your test suite right on the first try. Thanks, and it looks like you're in the lead!
The last 3 tests are incorrect.
Dimensions of matrices being concatenated are not consistent.
I admit they look wrong, but the actual text in the MATLAB code runs properly. I just re-scored some answers and they worked fine. It must be some kind of HTML display problem. I'll check into it.
Solution Comments
Show commentsProblem Recent Solvers56
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15529 Solvers
-
Find state names that end with the letter A
1175 Solvers
-
Read a column of numbers and interpolate missing data
2282 Solvers
-
14787 Solvers
-
7273 Solvers
More from this Author50
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!