Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

1 visualizzazione (ultimi 30 giorni)
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'

Risposte (1)

Birdman
Birdman il 7 Giu 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

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by