Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Error states 'Subscript indices must either be real positive integers or logicals' when trying to complete this for loop?

조회 수: 1 (최근 30일)
if true
Ti_in(1) = 120;
Ts_in(1) = 60;
rho_i = 920;
rho_s = 997;
Cp_i = 2100;
Cp_s = 4180;
r_i = 0.01;
r_s = 0.02;
L = 3;
Acs_i = pi*(r_i)^2;
Acs_s = pi*(r_s)^2 - pi*(r_i)^2;
Ip_i = 2*pi*r_i;
V_i = 0.003/(60*Acs_i);
V_s = 0.003/(60*Acs_s) ;
U=600;
range = [0:0.005:L];
for i = range
Ti_in(i) = Ti_in -((Ip_i*U)*(0.005+i-i)*(Ti_in-Ts_in)/(rho_i*Acs_i*Cp_i*V_i));
Ti_in
end
end
When trying to get the output of the iteration it says error 'Subscript indices must either be real positive integers or logicals'

답변 (1개)

Birdman
Birdman 2018년 6월 7일
You can not subscript element zero of an array. Change your for loop to
for i = 1:numel(range)
Ti_in(i) = Ti_in -((Ip_i*U)*(0.005+range(i)-range(i))*(Ti_in-Ts_in)/(rho_i*Acs_i*Cp_i*V_i));
Ti_in
end

제품

Community Treasure Hunt

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

Start Hunting!

Translated by