Problem creating array in for loop

1 次查看(过去 30 天)
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

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-2-16
编辑:KALYAN ACHARJYA 2019-2-16
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by