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
4 次查看(过去 30 天)
显示 更早的评论
y = randi([0, 11],uint32)
1 个评论
Ganesh
2024-5-30
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.
回答(1 个)
Manikanta Aditya
2024-5-30
编辑:Manikanta Aditya
2024-5-30
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!