Embedded code for Randi function.it generates 625 arrays to some values, I want to know why it is generated 625 arrays of random values in initial function
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
y = randi([0, 11],uint32)
1 comentario
Ganesh
el 30 de Mayo de 2024
I assume you mean that it creates an array with 625 values. I also assume that you do not intend to use the function "uint32()".
There is likely a variable in workspace with the name uint32 with a value of 25.
When you provide a single size, here uint32, to "randi()", it creates a matrix of size uint32*uint32, hence you get an array with 625 values. Reading the documentation related to the function "randi()" thoroughly will certainly help.
Respuestas (1)
Manikanta Aditya
el 30 de Mayo de 2024
Editada: Manikanta Aditya
el 30 de Mayo de 2024
The randi function in MATLAB generates uniformly distributed random integers in a specified interval. The syntax you’ve used, randi([0, 11],uint32), is not correct as the second argument to randi should be the size of the array you want to generate.
If you want to generate a 625-element array of random integers between 0 and 11, you should use:
y = randi([0, 11], [1, 625]);
disp(y);
This will create a 1x625 matrix y with each element being a random integer between 0 and 11.
If you’re seeing 625 arrays being generated, it’s likely due to a loop or other repeated call to randi in your code and also it might be due to a loop or function call not shown in the snippet you provided. Ensure that the context of the function call is appropriate and not wrapped in unnecessary loops unless required by your application.
I think this clarifies!
0 comentarios
Ver también
Categorías
Más información sobre Random Number Generation 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!