How to make a matrix only with 2 types of numbers randomly
Mostrar comentarios más antiguos
Hello,
It may sound a silly question but i cannot think in the desired solution. I need to make a matriz 1:24 only with values that might be 5 or 10? How can i make it randomly?
Example of the desired solution: [10 5 10 5 5 5 10 10 5 10 10 10 10 10 10 5 5 5 5 5 10 5 10 10]
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 18 de Dic. de 2012
Here's another way:
a = 5 * (randi(2, 1, 24)-1) + 5
3 comentarios
Image Analyst
el 18 de Dic. de 2012
Editada: Image Analyst
el 18 de Dic. de 2012
I hope this wasn't your homework! You didn't tag it as such. If it were I would have just given you a hint to use randi().
André Pacheco
el 18 de Dic. de 2012
Editada: André Pacheco
el 18 de Dic. de 2012
Image Analyst
el 18 de Dic. de 2012
If you have the Image Processing Toolbox you can use the new imquantize() function.
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!