MATLAB: Problem creating array in for loop

for loopMATLABmatrix array

Hi,
I am trying to create an array using a for loop but I keep getting an error
'Index in position 1 is invalid. Array indices must be positive integers or logical values.'
Any ideas how to solve it?
Thanks
Here is my code:
% Calculate coefficients of inversed function
coeff_IC1 = polyfit(y1, x1, 4);
coeff_EC1 = polyfit(y2, x2, 4);
% Calculate and plot inversed function y = xg(x)
valueExt_IC1 = zeros(3e5, 1);
valueP_IC1 = zeros(3e5,1);
for p_IC1 = -3e5:0
ext_IC1 = p_IC1 * (coeff_IC1(2) + (coeff_IC1(3) * p_IC1) + (coeff_IC1(4) * p_IC1^2) + (coeff_IC1(5) * p_IC1^3));
valueExt_IC1((p_IC1 + 1), 1) = ext_IC1;
valueP_IC1((p_IC1 + 1), 1) = p_IC1;
end
valueExt_EC1 = zeros(1.5e5, 1);
valueP_EC1 = zeros(1.5e5,1);
for p_EC1 = 0:1.5e5
ext_EC1 = p_EC1 *(coeff_EC1(2) + (coeff_EC1(3) * p_EC1) + (coeff_EC1(4) * p_EC1^2) + (coeff_EC1(5) * p_EC1^3));
valueExt_EC1((p_EC1 + 1), 1) = ext_EC1;
valueP_EC1((p_EC1 + 1), 1) = p_EC1;
end

Best Answer

This error occured when you tried to use index into an array indices those are not positive integers
for p_IC1 = -3e5:0
I have no idea what problems you are dealing , try to make positive indices, For more visit documentation check here