How to create a vector with elements randomly chosen from another vector?
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Moein M
 el 27 de Mzo. de 2020
  
    
    
    
    
    Respondida: Steven Lord
    
      
 el 27 de Mzo. de 2020
            Hello folks.
I have a column vector, each of whose elements is a row vector consisting of two elements (essentially a par):
a = [[A1 T1] ; [C1 G1] ; [T2 A2] ; [G2 C2]]
 How do I create another vector with the size 1*N, whose elements are randomly chosen from "a" ?
Note: The elements of the resulting vector can be repeated.
Thank you.
0 comentarios
Respuesta aceptada
  Steven Lord
    
      
 el 27 de Mzo. de 2020
        I have a column vector, each of whose elements is a row vector consisting of two elements
The common term for that is a matrix.
If you want to sample without replacement, use randperm to determine which rows of your matrix you want to include and then use subscripted indexing to extract the selected rows.
If you want to sample with replacement, use randi to generate the row indices then use subscripted indexing just like in the randperm (without replacement) case.
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Logical 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!

