How to make a repetitive random array with a curtain interval?

I need a array with 5000 increasing float and random numbers from 0 to 360 and also it should be repetitive inside like 0,.....,360,0,........,360,0.... and so on. Here my code without repetition feature:
a = 0;
b = 360;
% rng('shuffle');
r1 = sort((b-a)*rand(5000,1)+a,'ascend');

 Réponse acceptée

DGM
DGM le 4 Avr 2022
Modifié(e) : DGM le 4 Avr 2022
It's not really clear what the requirements are for cycle length and whether each cycle needs to end on specific values, but maybe this is a start.
In this example, each cycle is a fixed length, but the range varies.
a = 0;
b = 360;
ncycles = 10;
npoints = 500; % i'm using fewer points so the variation is visible
r1 = sort((b-a)*rand(npoints/ncycles,ncycles)+a,1,'ascend');
r1 = r1(:);
plot(r1)
Here's another way. In this example, the cycle length also varies.
a = 0;
b = 360;
ncycles = 10;
npoints = 500;
r2 = sort(ncycles*(b-a)*rand(npoints,1),1,'ascend');
r2 = mod(r2,360)+a;
clf
plot(r2)

1 commentaire

The cycle length is not a big deal for me. Therefore, this answer totally solved my problem, thanks for your answer

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange

Produits

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by