Could anyone help me how to generate the matrix in the following manner as described below

2 vues (au cours des 30 derniers jours)
I want to generate a matrix of size
(1500x1)
in which first 100 rows should be having the value of 1, next 200 rows should be having the value of 1 and 2 arranged randomly, next 300 should be having the value of 1,2 and 3 arranged randomly, next 400 rows should be having the value of 1,2,3 and 4 arranged randomly and next 500 rows should be having the value of 1,2,3, 4 and 5 arranged randomly.
Could anyone please help me on this.

Réponse acceptée

Bruno Luong
Bruno Luong le 4 Août 2021
Modifié(e) : Bruno Luong le 4 Août 2021
hi=repelem((1:5)',100*(1:5));
r=ceil(rand(size(hi)).*hi)

Plus de réponses (2)

Vignesh Murugavel
Vignesh Murugavel le 4 Août 2021
This should do it.
m1 = ones([100,1]);
m2 = randi([1 2],200,1);
m3 = randi([1 3],300,1);
m4 = randi([1 4],400,1);
m5 = randi([1 5],500,1);
Ans = [m1 ; m2;m3;m4;m5];

Rik
Rik le 4 Août 2021
Modifié(e) : Rik le 4 Août 2021
data=cell(5,1);
for n=1:numel(data)
data{n}=randi([1 n],n*100,1);
end
data=cell2mat(data);
size(data)
ans = 1×2
1500 1

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by