Randomize three chosen arrays in matlab

2 visualizaciones (últimos 30 días)
aboudeh kahaleh
aboudeh kahaleh el 13 de Oct. de 2016
Respondida: Jan el 20 de Oct. de 2016
Hello, On matlab I named A=[0,0,1] B=[0,1,0] C=[1,0,0]
and I want matlab to randomly pick from A B and C how can I do it please ?
In the end I want to display the randomly chosen array?
Please help
  1 comentario
Adam
Adam el 20 de Oct. de 2016
I guess you already have 3 answers, but 'randomly pick from A B and C' is not at all a clear definition of what you want. There are numerous different interpretations of what that means!

Iniciar sesión para comentar.

Respuestas (3)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam el 13 de Oct. de 2016
m=[A ; B ;C]
m(randi(3),:)
  1 comentario
Thorsten
Thorsten el 20 de Oct. de 2016
This picks randomly a column from m, but not randomly from A, B and C.

Iniciar sesión para comentar.


Thorsten
Thorsten el 20 de Oct. de 2016
Editada: Thorsten el 20 de Oct. de 2016
A = [0,0,1]; B=[0,1,0]; C=[1,0,0];
X = [A; B; C];
x = X(sub2ind(size(X), 1:3, randi(3, [1, 3])))

Jan
Jan el 20 de Oct. de 2016
A=[0,0,1]
B=[0,1,0]
C=[1,0,0]
R = [A(randi(3)), B(randi(3)), C(randi(3))]

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by