Generate clusters of points which are periodically spaced

1 次查看(过去 30 天)
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!

回答(1 个)

Guillaume
Guillaume 2018-4-13
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, [])

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by