Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
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'

Antworten (1)

Birdman
Birdman am 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

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by