Creating a random permutation that always start with a specific value
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Thomas Beerten
el 5 de Abr. de 2018
Respondida: Torsten
el 5 de Abr. de 2018
Dear all,
I want to create a vector of the size ten that starts with a the value one and the rest must be random. Therefore I wanted to do the following: N = [1 randperm(9)]. However, randperm only returns the values between 1 and 9 in such a case. Is there anyone who knows how this works or knows another function that could help me with my problem.
Kind regards, Thomas
0 comentarios
Respuesta aceptada
Birdman
el 5 de Abr. de 2018
It sounds like randi function can help you. First argument specifies the interval that integer values will be generated. Second and third argument specifies the number of row and column respectively.
N=[1 randi([2 9],1,8]
2 comentarios
Birdman
el 5 de Abr. de 2018
No that is not possible with randi. You may use randsample as follows to uniquely create numbers:
randsample(1:10,10)
But the order will be random.
Más respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!