How to generate a rhythm that is based on an algorithm in matlab?

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Jan. 2022
a = 5, b = 13
a = 5
b = 13
positions = floor(linspace(1, (b+1), a+1))
positions = 1×6
1 3 6 8 11 14
rhythm = zeros(1,b);
rhythm(positions(1:end-1)) = 1
rhythm = 1×13
1 0 1 0 0 1 0 1 0 0 1 0 0

Weitere Antworten (1)

Bjorn Gustavsson
Bjorn Gustavsson am 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 Kommentare
Kevin
Kevin am 10 Jan. 2022
Yes, I think I understand the algortihm right now, but I don't know how to implement it in matlab since I'm not too experienced with matlab. I know to use repelem so I now have the 1s and 0s like this:
0 0 0 0 0 0 0 0 1 1 1 1 1
How do I make them in pairs?
Bjorn Gustavsson
Bjorn Gustavsson am 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by