Error in the 'for' function not storing values

2 views (last 30 days)
I wrote this piece of code, and i can't understand what is wrong, keeps giving me this error:
*Attempted to access m(0); index must be a positive integer or logical.
Error in Solaretermico_codice (line 21) Ts(i) = (eff*Qs+eff*Qa+m(15-Ts(i-1)))/(Cp*M);*
Here it's the code:
%%Definizione Dati
n = size(orario,1);
eff = 0.8; % Efficienza Serpentina
Cp = 4186; % Calore Specifico dell'acqua
m = portata; % Consumo acqua calda in l/s
M = 500; % Capienza Serbatoio
%%Inizializzazione Variabili
Ts = zeros(n,1);
Ts(1) = 15; % in gradi °C
%%Inizio Programma
for i=2:n
if Ts < 45;
Qs = radiazione*4.9*0.7;
Qa = 6000;
elseif Ts < 55;
Qs = radiazione*4.9*0.7;
Qa = 0;
end
Ts(i) = (eff*Qs+eff*Qa+m*Cp(15-Ts(i-1)))/(Cp*M);
end
i'm sry if its in italian, i'll attach the file with the variables.
What i'm doing wrong? Also the Ts variable starts at 15 and then it creates 48 zeros, i'm missing something so that if saves the new Ts calculated at the end of the 'for' cycle?

Accepted Answer

Star Strider
Star Strider on 15 May 2014
The line that threw the error is not the same statement of the line that is in the code you posted. The current one is correct in that there is no subscript reference for m. Assuming no other errors, the code you posted should run.
  6 Comments
Giulio
Giulio on 15 May 2014
thank you for the encouragement! i changed Cp to 4.186 from 4186 and now i'm having decent results! but i'm seeing that the results are all in the form of 5.73 or a little bit higher... now it got me thinking that what i'm calculating is not the tank temperature, but the gain in °C made each 30 mins, that is why i'm finding such small values.
Star Strider
Star Strider on 15 May 2014
My pleasure!
It would seem to me that the gain in tank temperature is the important variable. That’s the energy capture and storage.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!