Im using randsample() but im getting an error

35 visualizaciones (últimos 30 días)
Tariq Hammoudeh
Tariq Hammoudeh el 6 de En. de 2022
Comentada: Walter Roberson el 7 de En. de 2022
Im using randsample to make the program choose a random element from an array,
A=[2 3 4 5];
random=randsample(A,1)
but im getting an error that says 'randsample' requires Statistics and Machine Learning Toolbox.
So how can i make it work, or is there any other way i can make a random selection.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 7 de En. de 2022
@Tariq Hammoudeh yes, randsample requires the Statistics and Machine Learning Toolbox. If you just want to choose one random element from this array, you could do something like
A = [2 3 4 5];
randomValue = A(randi(length(A),1));
  6 comentarios
Tariq Hammoudeh
Tariq Hammoudeh el 7 de En. de 2022
y=zeros(1,36)
if isequal(x,one)
y(1)=1;
y(2)=1;
......
But whenever i run the code, all the elements of y stay zero, nothing becomes 1. How can i fix it.
Walter Roberson
Walter Roberson el 7 de En. de 2022
I would say... don't do that.
one=readmtarix();
two=readmatrix();
three=readmatrix();
A = {one two three};
x = randi(length(A));
board_configuration = A{x};
if x == 1
...
elseif x == 2
...
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by