Generate clusters of points which are periodically spaced

조회 수: 2 (최근 30일)
supernoob
supernoob 2018년 4월 13일
답변: Guillaume 2018년 4월 13일
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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by