Borrar filtros
Borrar filtros

question on generating random numbers

1 visualización (últimos 30 días)
John
John el 7 de Sept. de 2013
Here is my matlab code S{1,2} = [0,1,3,6];
S{1,5} = [0,2]
S{1,4} = [0,4,7]; The above code means that an arc say (1,2) has set [0,1,3,6] and arc(1,5) has set [0,2] and so on. I would like to create these sets randomly for each arc.( the sets should have integer numbers between 0-10). Please help!

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Sept. de 2013
Editada: Azzi Abdelmalek el 7 de Sept. de 2013
k=100 % number of random arcs
out=arrayfun(@(x) sort(randperm(11,randi(10)+1)-1),1:k,'un',0);
celldisp(out)

Más respuestas (1)

Youssef  Khmou
Youssef Khmou el 7 de Sept. de 2013
John
Using random permutation can be helpful, start from this prototype :
S=cell(10,1);
for n=1:10
S{n}=randperm(10);
end
you can add an integer random number n to truncate S{i} each time .

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by