Borrar filtros
Borrar filtros

picking numbers from matrix

1 visualización (últimos 30 días)
Berfin Çetinkaya
Berfin Çetinkaya el 17 de Mzo. de 2022
Comentada: Berfin Çetinkaya el 17 de Mzo. de 2022
I have a matrix and it contains some numbers. I want to pick a random number from each column in this matrix and print it in another matrix (one of the numbers excluding 0). My new matrix should have at least 50 rows. So I want to select and print the random values multiple times. But I don't want to print the 0 values to the new matrix.
give examples :
my matrix:
0 4 8
5 0 0
0 4 6
2 8 0
0 0 7
new matrix:
2 4 6
5 8 6
5 4 7
5 4 8
how can I do that?
Thank you,
Berfin.
  2 comentarios
Matt J
Matt J el 17 de Mzo. de 2022
Editada: Matt J el 17 de Mzo. de 2022
This question seems essentially the same as,
Can't you just apply that solution 50 times (in a loop, that is)?
Berfin Çetinkaya
Berfin Çetinkaya el 17 de Mzo. de 2022
I don't know how to apply it in loop

Iniciar sesión para comentar.

Respuesta aceptada

David Hill
David Hill el 17 de Mzo. de 2022
A=[0 4 8
5 0 0
0 4 6
2 8 0
0 0 7];
for k=1:size(A,2)
r=unique(A(:,k));
r=r(r~=0);
B(:,k)=r(randi(length(r),50,1));
end

Más respuestas (0)

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