Effacer les filtres
Effacer les filtres

Generate clusters of points which are periodically spaced

3 vues (au cours des 30 derniers jours)
supernoob
supernoob le 13 Avr 2018
Hi there, I'd like to find an efficient way of generating clusters of points where each cluster is periodically spaced. So for example, say for a given frequency f I want to generate a little cluster of points, starting at t=0, at each half period with some spread in time. So the periodic spacing of my points is the period/2. The cluster could be, say, 6 points which are spread by, say the period/20. So if my frequency was 1 Hz, T/2 = 0.5s. I want to generate some 'time points' starting at t=0 which would have 3 points spaced by 0.5s/10, then centered at T/2 6 points spread by 0.5s/10, then again at T, then again at 3/2T until I reach a specified maximum time. I can think of some fairly burdensome brute force approaches to this problem but something more elegant and efficient would be appreciated. Thanks!

Réponses (1)

Guillaume
Guillaume le 13 Avr 2018
Generate your main period as a row vector, your cluster spread as a column vector of delta, add them and reshape into a vector and you're done:
mainperiod = 0.5;
clusterperiod = mainperiod / 20;
numpoints = 100;
halfclustercount = 3;
mainpoints = 0: mainperiod : mainperiod * (numpoints - 1);
clusterdelta = (-halfclustercount : halfclustercount) * clusterperiod;
fullvector = reshape(mainpoints + clusterdelta.', 1, [])

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by