Problem creating array in for loop

조회 수: 3 (최근 30일)
Paul Van der Merwe
Paul Van der Merwe 2019년 2월 16일
편집: KALYAN ACHARJYA 2019년 2월 16일
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에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by