Index exceeds array bounds.

6 views (last 30 days)
clc; clear;
dt = 0.5;
Glucose = zeros(1,361);
Glucose(1,1) = 6000;
Glucose_Released = 110;
Glucose_Used = zeros(1,361);
Usage_Fraction = zeros(1,361);
t = 0:dt:180; % We need to generate a time vector for our plot
for k = 2:length(t)
Glucose_Used(k) = Glucose(k) * Usage_Fraction(k); % Based on Euler?sformula
Glucose(k-1) = Glucose(k) + [Glucose_Released(k) - Glucose_Used(k)]*dt;
end
Please help!!
  3 Comments
Sudhaunsh Deshpande
Sudhaunsh Deshpande on 28 Apr 2021
It did kinda work, the values are now zero which means that my guy is dead, but hey atleast the damn thing runs!

Sign in to comment.

Accepted Answer

David Fletcher
David Fletcher on 28 Apr 2021
You have defined Glucose_Released as a scaler value
Glucose_Released = 110;
You are then trying to index it, which will cause an error
Glucose_Released(k)
  3 Comments
Sudhaunsh Deshpande
Sudhaunsh Deshpande on 28 Apr 2021
Okay that actually makes sense
thank you :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!