Index exceeds the number of array elements?
Afficher commentaires plus anciens
Hello,
I am trying to extract data from Xsteam.I am trying to retrive data with respect to temperature. the code is as follows.
p = 10;
a = 1000;
b = 0.1;
rho_s = zeros(1,((a-1)/b));
L = length(rho_s);
for i = 1:L
T(i)= 1+b*i;
rho_s(i) =XSteam('rho_pT', p, T(i));
drho_s_dT = (rho_s(i+1)-rho_s(i))/(T(i+1)-T(i));
end
when i run this code I am getting an error as "Index exceeds the number of array elements". Can some one check and help me how can I do this.
6 commentaires
John Marriott
le 27 Mai 2020
Hi
on this line - drho_s_dT = (rho_s(i+1)-rho_s(i))/(T(i+1)-T(i)); you are trying to take the ith+1 element of rho_s without having created it first. E.g on the first iteration you are trying to subtract the first value in rho_s from the value generated in the second iteration of the loop but this hasnt been created yet
perhaps instead you could use
for i = 1:length(rho_s)
T(i)= 1+b*i;
rho_s(i) =XSteam('rho_pT', p, T(i));
if i >=2
drho_s_dT(i) = (rho_s(i)-rho_s(i-1))/(T(i)-T(i-1));
end
end
also i added a loop index to the variable drho_s_dT becasue it didnt make sense doing pressumably you want to save each time its performing this calculation or else what is the point?
vishnuvardhan naidu tanga
le 27 Mai 2020
Modifié(e) : Rik
le 27 Mai 2020
vishnuvardhan naidu tanga
le 27 Mai 2020
John Marriott
le 27 Mai 2020
Ok - the columns of which variable outputs NaN?- it doesnt return NaN when I run it - are you using the XSteam function posted by Rik?
vishnuvardhan naidu tanga
le 27 Mai 2020
Modifié(e) : vishnuvardhan naidu tanga
le 27 Mai 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Multidimensional Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!