Error in the 'for' function not storing values
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!