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/How can I handle ''index exceeds the number of array elements (1)'' error?
Next
Answered
thereseblanda
  • 3
thereseblanda
Asked: July 1, 20222022-07-01T11:57:01+00:00 2022-07-01T11:57:01+00:00In: Error

How can I handle ”index exceeds the number of array elements (1)” error?

  • 3

. Advertisement .

..3..

. Advertisement .

..4..

I’m new on Matlab. I’m facing the error ”index exceeds the number of array elements (1)” when I run this line:

P2(i) = (V2(i) - V0) / C2;

The code runs without a hitch on my computer, but when transferred and executed on another, it displays the error message.

Here is my code:

dt = 0.005; N = 200; %(s)
P3s = 2; P3d = 23.5; %(mmHg)
V2(1) = .475; %(L)
V0 = .06; %(L)
C2 = 0.05; %(L/mmHg)
R1 = 30; R2 = 30; %(mmHg*s/L)
P1 = 11; %(mmHg)
P3(1:120) = P3s;
P3(121:200) = P3d;
t = 0:dt:(N-1)*dt;
plot(t, P3)
xlabel('Time (s)'), ylabel('Pressure (mmHg)')
for i = 1:N
    P2(i) = (V2(i) - V0) / C2;
    if P2(i) > P3(i); Q3(i) = (P2(i) - P3(i)) / R2;
        else Q3(i) = 0;
    end
    Q1(i) = (P1 - P2(i)) / R1;
    Q2(i) = Q1(i) - Q3(i);
    P2(i+1) = P2(i) + Q2(i)*dt;
end
tp = 0:dt:N*dt;
figure
plot(tp, P2)
xlabel('Time (s)'), ylabel('P2 (mmHg)')

I am looking forward to gaining some knowledge from all experts. Thank you, guys!

  • 1 1 Answer
  • 72 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    hdtutoria Expert
    2022-07-01T15:25:52+00:00Added an answer on July 1, 2022 at 3:25 pm

    The cause: I think this error happens because in your code, you only define V2(1); you do not expand the V2 variable’s size. Therefore, I believe that the code that gives values to V2(i+1) in your for loop is missing. It can run in your computer because another script’s V2 variable with the correct size is in your workspace, which prevents the code from yelling at you.

    Solution: You can fix this error by adding a line in your for loop, as the following:

    for i = 1:N
          ...
          V2(i+1) = *equation*
    end

    → Read more: How to Fix The Error “Index Exceeds The Number of Array Elements (1)”? – A Complete Guide

    • 3
    • 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.