Index exceeds the number of array elements

5 次查看(过去 30 天)
Hi,
I got the error written below.
Index exceeds the number of array elements. Index must not exceed 2.
CHG_step = CHG_step(1:Inputs_RCC.CyclesxcRate); % Based on how many cycles x C-rate
Line 73 is written in bold black.
Tolerance_D = abs(Files.PreProcessedData{idx}.Current_A - Rated_Cap*Inputs_RCC.cRate_DCH) < AcceptedErrorCurrent;
RCC_Step_CHG = {}; % Find the unique steps for the Discharge rates
for i = 1:size(Inputs_RCC.cRates_CHG,1)
Tolerance_C = abs(Files.PreProcessedData{idx}.Current_A - Rated_Cap*cell2mat(Inputs_RCC.cRates_CHG(i))) < AcceptedErrorCurrent;
% Record the unique step if it's CC step, charge and the C-Rate is the one from the pulses
if i == 1
CHG_step = Files.PreProcessedData{idx}.FlagUniqueStep(Tolerance_C & contains(Files.PreProcessedData{idx}.Mode, "C_CC"));
CHG_step = unique(CHG_step);
CHG_step = CHG_step(CHG_step > Cap_Check_Steps(end)); % Take the steps after the cap check not to repeat them
CHG_step = CHG_step(1:Inputs_RCC.CyclesxcRate); % Based on how many cycles x C-rate
RCC_Step_CHG = [RCC_Step_CHG; num2cell(CHG_step)];
This is for test protocol of battery. So, the protocol is shown below:
"CHG step (Charge step), C-rates are C/, C/3, C/2, 1C and 2C."
Charge Steps 3 cycles at each C-rate
C/5 with C/20 cut-off
C/3 with C/20 cut-off
C/2 with C/20 cut-off
1C with C/20 cut-off
"2C
with C/20 cut-off"
Can someone please help me?

回答(1 个)

Torsten
Torsten 2024-7-30
移动:Torsten 2024-7-30
My guess is that when you reach this line of your code
CHG_step = CHG_step(1:Inputs_RCC.CyclesxcRate); % Based on how many cycles x C-rate
CHG_step is an array of size (1x2). But the variable "Inputs_RCC.CyclesxcRate" is greater than 2. So you try to access elements of CHG_step that don't exist.
  2 个评论
Tugce
Tugce 2024-7-30
Thank you. Yes, you're right, but how can I fix or change it?
Torsten
Torsten 2024-7-30
编辑:Torsten 2024-7-30
Since you are the only person who knows what's going on in your code, you are also the only person who can find a proper solution for this array access error.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by