Borrar filtros
Borrar filtros

Creating a function that does the same as myrandperm(n,k)

4 visualizaciones (últimos 30 días)
I have to create a function,which does the same as myrandperm(n,k). I thought of creating a for loop which goes from 1 to k in which an array p(i) gets initialised by a random integer of an array n. And then p(i) gets deleted from from the array n.
But I didnt found a function that gives me a random integer from an array.
Do you guys have any ideas?

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Nov. de 2020
randi(length(n))
  4 comentarios
Walter Roberson
Walter Roberson el 19 de Nov. de 2020
random index = randi(length(d))
random value = d(random index)
delete entry "random index" from d
lathe, rinse, repeat
Furkan Karaman
Furkan Karaman el 19 de Nov. de 2020
@Rik ,because our professor does not want it, as a challenge for us.
@Walter thank you

Iniciar sesión para comentar.

Más respuestas (0)

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