MATLAB Answers

0

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

Asked by Tristan Phillips-Page on 7 Jun 2018
Latest activity Answered by Birdman
on 7 Jun 2018
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'

  0 Comments

Sign in to comment.

1 Answer

Answer by Birdman
on 7 Jun 2018

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

  0 Comments

Sign in to comment.