Embedded code for Randi function.it generates 625 arrays to some va... (2024)

33 views (last 30 days)

Show older comments

leena on 30 May 2024 at 7:47

  • Link

    Direct link to this question

    https://ch.mathworks.com/matlabcentral/answers/2123901-embedded-code-for-randi-function-it-generates-625-arrays-to-some-values-i-want-to-know-why-it-is-ge

  • Link

    Direct link to this question

    https://ch.mathworks.com/matlabcentral/answers/2123901-embedded-code-for-randi-function-it-generates-625-arrays-to-some-values-i-want-to-know-why-it-is-ge

Edited: Manikanta Aditya on 30 May 2024 at 8:33

y = randi([0, 11],uint32)

1 Comment

Show -1 older commentsHide -1 older comments

Ganesh on 30 May 2024 at 8:04

Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/2123901-embedded-code-for-randi-function-it-generates-625-arrays-to-some-values-i-want-to-know-why-it-is-ge#comment_3175916

  • Link

    Direct link to this comment

    https://ch.mathworks.com/matlabcentral/answers/2123901-embedded-code-for-randi-function-it-generates-625-arrays-to-some-values-i-want-to-know-why-it-is-ge#comment_3175916

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.

https://www.mathworks.com/help/matlab/ref/randi.html

Sign in to comment.

Sign in to answer this question.

Answers (1)

Manikanta Aditya on 30 May 2024 at 7:59

  • Link

    Direct link to this answer

    https://ch.mathworks.com/matlabcentral/answers/2123901-embedded-code-for-randi-function-it-generates-625-arrays-to-some-values-i-want-to-know-why-it-is-ge#answer_1465306

  • Link

    Direct link to this answer

    https://ch.mathworks.com/matlabcentral/answers/2123901-embedded-code-for-randi-function-it-generates-625-arrays-to-some-values-i-want-to-know-why-it-is-ge#answer_1465306

Edited: Manikanta Aditya on 30 May 2024 at 8:33

Open in MATLAB Online

Hi @leena,

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);

Columns 1 through 30 4 3 2 5 2 1 4 2 0 9 5 3 3 2 5 6 7 7 0 6 10 0 4 10 5 9 2 6 11 11 Columns 31 through 60 9 3 9 0 11 7 6 1 3 6 4 6 2 1 11 4 9 10 2 9 11 8 3 11 7 0 5 8 5 0 Columns 61 through 90 4 10 7 10 1 1 9 7 10 9 9 3 9 4 11 4 10 4 6 11 5 5 8 2 6 2 5 3 2 5 Columns 91 through 120 3 0 0 0 2 0 10 9 7 11 2 3 7 7 3 8 0 9 6 8 5 0 2 0 0 10 5 7 6 10 Columns 121 through 150 0 3 5 1 6 7 8 9 5 1 3 2 8 7 8 6 4 3 8 1 5 7 3 4 1 5 1 6 6 4 Columns 151 through 180 4 11 7 10 4 10 7 10 7 11 3 2 0 7 5 4 7 2 9 1 8 7 8 7 11 5 8 11 7 10 Columns 181 through 210 9 2 4 6 0 6 4 11 4 2 11 8 5 8 9 4 5 11 11 11 6 7 5 11 11 0 4 11 10 8 Columns 211 through 240 6 6 11 2 2 1 11 1 9 9 10 6 11 10 9 8 9 9 2 5 10 11 4 6 3 0 7 11 11 4 Columns 241 through 270 4 2 3 2 6 7 3 4 10 6 9 3 4 3 1 6 7 1 11 6 8 6 10 5 10 9 2 6 6 1 Columns 271 through 300 6 1 10 9 6 3 5 2 1 1 11 11 11 0 10 11 2 1 4 0 6 4 10 3 1 11 6 11 6 9 Columns 301 through 330 4 6 6 11 0 3 5 0 4 6 7 11 4 11 8 8 4 4 9 7 9 8 5 5 7 2 0 9 0 7 Columns 331 through 360 1 9 0 4 8 3 3 5 11 11 6 4 4 0 9 2 9 3 11 6 0 0 1 2 6 2 1 10 3 5 Columns 361 through 390 1 8 2 11 5 11 2 3 4 6 9 6 9 3 2 7 1 10 3 11 3 5 1 6 5 9 6 10 0 5 Columns 391 through 420 4 7 0 4 7 5 11 2 10 9 6 9 6 0 1 11 0 3 5 7 6 0 0 8 1 1 8 0 9 9 Columns 421 through 450 6 10 6 10 6 4 7 7 3 10 9 4 10 0 5 3 6 5 8 11 3 0 10 1 4 8 7 3 11 0 Columns 451 through 480 7 2 1 11 10 4 4 11 8 7 0 7 3 10 9 11 8 10 8 1 1 9 7 3 10 4 7 5 5 8 Columns 481 through 510 1 1 7 4 8 9 5 1 8 10 10 3 7 10 10 10 10 8 6 3 11 6 2 9 7 2 9 9 0 2 Columns 511 through 540 4 0 8 1 7 9 4 0 9 9 8 9 3 11 5 10 11 8 11 4 9 2 5 0 10 2 7 11 11 11 Columns 541 through 570 10 8 3 3 0 8 7 1 4 11 9 8 6 2 4 10 8 8 1 1 1 7 0 3 1 6 3 8 2 9 Columns 571 through 600 9 6 3 5 10 4 3 3 7 6 7 3 6 3 5 10 0 0 0 11 3 2 6 7 9 4 8 0 4 6 Columns 601 through 625 5 5 9 5 3 5 2 6 0 3 11 7 1 7 3 5 1 9 2 2 11 3 5 1 11

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 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Tags

  • embedded coder
  • matlab function
  • random number generator

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Embedded code for Randi function.it generates 625 arrays to some va... (4)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

Embedded code for Randi function.it generates 625 arrays to some va... (2024)
Top Articles
Latest Posts
Article information

Author: Tish Haag

Last Updated:

Views: 5613

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.