Index exceeds the number of array elements?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
vishnuvardhan naidu tanga
el 27 de Mayo de 2020
Comentada: Ameer Hamza
el 27 de Mayo de 2020
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 comentarios
John Marriott
el 27 de Mayo de 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
el 27 de Mayo de 2020
Editada: vishnuvardhan naidu tanga
el 27 de Mayo de 2020
Respuesta aceptada
Ameer Hamza
el 27 de Mayo de 2020
It seems that you are trying to find a derivative of rho_s w.r.t. T, you can use gradient() function
p = 10;
a = 1000;
b = 0.1;
rho_s = zeros(1,((a-1)/b));
L = length(rho_s);
T = zeros(1, L);
for i = 1:L
T(i)= 1+b*i;
rho_s(i) =XSteam('rho_pT', p, T(i));
end
drho_s_dT = gradient(rho_s, T);
2 comentarios
vishnuvardhan naidu tanga
el 27 de Mayo de 2020
Editada: vishnuvardhan naidu tanga
el 27 de Mayo de 2020
Ameer Hamza
el 27 de Mayo de 2020
This is probably caused by the thermodynamical equation implemented in XSteam() and not a MATLAB specific issue. You will need to understand the equations and the implementation of this function to see what might be going wrong. Also, you aren't passing variable 'p' in your code, which might be causing the issue.
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!