Problem creating array in for loop

3 Ansichten (letzte 30 Tage)
Paul Van der Merwe
Paul Van der Merwe am 16 Feb. 2019
Bearbeitet: KALYAN ACHARJYA am 16 Feb. 2019
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

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 16 Feb. 2019
Bearbeitet: KALYAN ACHARJYA am 16 Feb. 2019
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

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by