# How can i generate data randomly in MATLAB

1 view (last 30 days)
Med Future on 4 Mar 2022
Commented: Walter Roberson on 6 Mar 2022
Hello Everyone, I hope you are doing well
I have the following code. which generate 5 level of different values.as you can see in plot
I want to generate random level upto 32 for random value from 1 to 1000
How can i do that in matlab
VALUE = [100 300 600 700 1000 ];
out2 = repmat(VALUE,1,ceil(4000/numel(VALUE)));
scatter(1:length(out2),out2)
KSSV on 4 Mar 2022
What do you mean by upto 32?

Arif Hoq on 4 Mar 2022
try this:
VALUE=1:(1000-1)/31:1000
VALUE = 1×32
1.0000 33.2258 65.4516 97.6774 129.9032 162.1290 194.3548 226.5806 258.8065 291.0323 323.2581 355.4839 387.7097 419.9355 452.1613 484.3871 516.6129 548.8387 581.0645 613.2903 645.5161 677.7419 709.9677 742.1935 774.4194 806.6452 838.8710 871.0968 903.3226 935.5484
out2 = repmat(VALUE,1,ceil(4000/numel(VALUE)));
scatter(1:length(out2),out2);
Med Future on 6 Mar 2022
@Walter Roberson so i cant reshape it into 1000?
Walter Roberson on 6 Mar 2022
level = 17; %randi([2 32], 1, 100);
[M,N]=size(level);
for j = 1:size(level,2)
prf=randi([1 1000], 1,level(j));
size(prf)
out = repmat(prf,1,ceil(1000/numel(prf)))
whos
end
ans = 1×2
1 17
out = 1×1003
941 438 290 294 399 989 876 941 501 786 405 23 422 262 95 118 716 941 438 290 294 399 989 876 941 501 786 405 23 422
Name Size Bytes Class Attributes M 1x1 8 double N 1x1 8 double ans 1x2 16 double j 1x1 8 double level 1x1 8 double out 1x1003 8024 double prf 1x17 136 double
Notice that out is length 1003. You cannot reshape() 1003 into 1000.
What you can do is
out = out(1:1000);
and you could reshape() that

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!