How to generate a rhythm that is based on an algorithm in matlab?
1 view (last 30 days)
Show older comments
I want to generate a rhythm in Matlab that consists of 1s and 0s, but I don't know how to start.
So I know that I have a variable a = the amount of 1s, b = the length c = the amount of 0s
So that would give a = a (you can choose a number), b = b (you can choose a number) and c = b-a
For the rhythm I want to have all the 1s divided as evenly as possible throughout the 0s (euclidean algorithm).
As an example:
b = 13 and a = 5
So it might be good to put every 1 together with a 0, that would be:
01 01 01 01 01 000
Now you have three 0s and five pairs of 01s.
Now to divide 0 evenly with the pairs:
010 010 010 0101
Now to divide the two 01s evenly into the three 010s
0100101001010
This is as evenly we can distribute five 1s over the length of 13.
Right now I want to create a script in matlab which give you a rhythm automatically when you type in a random a and b (given that b > a)
Any help would be appreciated.
0 Comments
Accepted Answer
Walter Roberson
on 13 Jan 2022
a = 5, b = 13
positions = floor(linspace(1, (b+1), a+1))
rhythm = zeros(1,b);
rhythm(positions(1:end-1)) = 1
More Answers (1)
Bjorn Gustavsson
on 10 Jan 2022
1, You search for some description of the algorithm that allows you to implement it. For example 5 minutes on googles first page of results and I got to this nice description of the algorithm in practice: euclidean-rhythms
2, Try to implement the algorithm by hand for some small example with pen and paper, or some small markers or the like. This will help you get the hang of what's to be done. Preferably do a couple to see that your algorithm-understanding is general enough.
3, implement it.
4, test
5, if fail return to 3
HTH
2 Comments
Bjorn Gustavsson
on 10 Jan 2022
If you're that new to matlab the best way forward for you is to walk/work through the Matlab on-ramp material, which should get you started with the focus on what sections you need more as you see fit in a much more efficient manner than we can ever cover with answers to specific problem-questions.
HTH
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!