Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Why do I get the trouble “index in position 1 exceeds array bounds (must not exceed 1)”?
Next
Answered
Mia Goncalves
  • 14
Mia Goncalves
Asked: May 12, 20222022-05-12T11:48:10+00:00 2022-05-12T11:48:10+00:00In: matlab

Why do I get the trouble “index in position 1 exceeds array bounds (must not exceed 1)”?

  • 14

. Advertisement .

..3..

. Advertisement .

..4..

I am working on matlab, but I found the following warning message:

Index in Position 1 exceeds array bounds (must not exceed 100).

Is there any way to stabilize the issue “index in position 1 exceeds array bounds (must not exceed 1)” ? I read a lot of topics about this, but all of them were trying to install anything. Is this the correct way, or any recommendation for me? Please find the beginning command below:

alpha = 0.5;
 w = gamma_rdn(M,alpha);
 x1 = (0.0001:0.001:1); % For plot
 
 figure(5)
 subplot(2,1,1);hist(w);title('Histogram of Gamma RDN');
 subplot(2,1,2);plot(x1,pdf('gam',x1,alpha,1));title('Theoretical Gamma Density with \alpha = 0.5');
 axis([0 1 0 100]);
 
 % The gamma_rdn function is implemented as follows:
 function[w] = gamma_rdn(M,alpha)
  % Generate random numbers from the gamma distribution with parameter
  % alpha <= 1, beta = 1
  pe = exp(1);
  w = zeros(M,1);
  u = rand(100,1);
  b = (alpha + pe)/pe;
  i = 0;
  j = 0;
  while j < M
  i = i+1;
  y = b*u(i,1);
  if y <= 1
  z = y^(1/alpha);
  i = i+1;
  if u(i,1) <= exp(-z)
  j = j+1;
  w(j,1) = z;
  else
  i = i+1;
  end
  else
  z = -log((b-y)/alpha);
  i = i+1;
  if u(i,1) <= z^(alpha - 1)
  j = j+1;
  w(j,1) = z;
  else
  i = i+1;
  end
  end
  end
  if i > 95
  u = rand(100,1);
  i = 0;
  end
 end
array bounds (must not exceed 1)
  • 1 1 Answer
  • 983 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-01T01:11:30+00:00Added an answer on June 1, 2022 at 1:11 am

    The cause: This error is because while loop causes y to become invalid if i exceeds100 (say i=101). It means that you’re trying to access U(101,1) but the U size is (100).

    Solution: Let’s consider a larger size like u= rand(10000),1).

    • 13
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.