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');

 Accepted Answer

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 Comment

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

Sign in to comment.

More Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 4 Apr 2022

Commented:

on 4 Apr 2022

Community Treasure Hunt

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

Start Hunting!