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 Center および File ExchangeResizing 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