Help! Keep getting error index exceeds the number of array elements(0).

% function [meanTot, stdTot] = RQpolicy_no(R1)
% Inventory system applying (R,Q) policy.
% Given reorder points, the function returns mean total cost and standard deviation.
function [meanTot, stdTot] = RQ_Test(R1)
n = 10; % Number of runs
lambda = 10; % Demand rates
L = 1; % Lead times
b = 20; % Backorder cost
h = 1; % Holding cost
A = 100; % Order cost
% The batch quantities by the EOQ formula
Q1 = round(sqrt(2*A*lambda/h));
costVector = []; % Vector with total cost for the runs
summa = 0; % Sum of total costs for all runs
for j = 1:n
% Creates points in time when demand will occur for each warehouse
% Times between customers are exp(lambda) distributed
nbrOfEvents = 30000;
u = rand(1,nbrOfEvents);
y = -log(1-u)/lambda;
T = cumsum(y);
stopTime = min(T(nbrOfEvents));
time = 0;
invLevel = 0; % Inventory levels
invPos = 0; % Inventory positions
invTime = []; % Arrival times for units in inventory
incom = []; % Arrival times for incoming items
backTime = []; % Times when backorders have occurred
timeInStock = 0; % Accumulated time in stock
54
timeInBackorder = 0; % Accumulated time in backorder
orderCost = 0; % Cost for all orders during simulation
Ntot = 0; % Number of customers during simulation
N1 = 0; % Number of backorders during simulation
% The first tenth of the time is start-up time
transientTime = stopTime/10;
while time < stopTime,
if time < transientTime,
timeInStock = 0;
timeInBackorder = 0;
end
% A trick to determine the next event
if isempty(incom),
incom = realmax;
end
% Determines the next event and the time when it happens
[time, event] = min([T(1) incom(1)]);
if incom(1) == realmax,
incom = [];
end
% A customer arrives at retailer 1
if event == 1,
Ntot = Ntot + 1;
% If there is stock on hand
if invLevel >= 1,
timeInStock = timeInStock + time - invTime(1);
invTime = invTime(2:length(invTime));
invLevel = invLevel - 1;
invPos = invPos - 1;
% Orders new items while the inventory position is less than R
55
while invPos <= R1,
orderCost = orderCost + A;
invPos = invPos + Q1;
for k = 1:Q1
incom = [incom time+L1];
end
end
% If there are no items in stock, the demanded item is backordered
else
N1 = N1 + 1;
backTime = [backTime time];
invLevel = invLevel - 1;
invPos = invPos - 1;
% Orders new items while the inventory position is less than R
56
while invPos <= R1,
orderCost = orderCost + A;
invPos = invPos + Q1;
for k = 1:Q1
incom = [incom time+L];
end
end
end
T = T(2:length(T));
end
if ~isempty(invTime),
for k = 1:length(invTime),
timeInStock = timeInStock + time - invTime(1);
invTime = invTime(2:length(invTime));
end
end
end
57
%%Partition%%
if ~isempty(backTime),
for k = 1:length(backTime),
timeInBackorder = timeInBackorder + time - backTime(1);
backTime = backTime(2:length(backTime));
end
end
end
stopTime = stopTime - transientTime;
% fillrate1 = 1 - N1/N1tot;
% The costs are calculated
orderCost = orderCost/stopTime;
holdCost = timeInStock*h/stopTime;
backCost = timeInBackorder*b/stopTime;
totCost = orderCost + holdCost + backCost;
costVector = [costVector totCost];
summa = summa + totCost;
% fillVector1 = [fillVector1 fillrate1];
meanTot = (1/n*summa);
end
Could someone help me with this? I have no idea why this is really happening!

댓글 수: 4

Code has been updated, found some faults else where but the problem still exists!
How do we reproduce the error.
It would be helpful if you can specify the error message and your inputs to the function, to reproduce the error.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 2월 23일

댓글:

2020년 3월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by