loops

1 visualización (últimos 30 días)
ricco
ricco el 5 de Nov. de 2011
Is there a better way of calculating values from within a matric without the use of a loop. For example: I need to calculate the density of freshwater, so I use a well known equations which calculates density. The change in density is due to the change in temperature. The loop that I set up runs through the matrix of temperature and calculates the density at each point.
for i=1:size(temp,1); rho(i,:)=(1-((temp(i,:)+288.9414)./(508929.2.*(temp(i,:)+68.12963))).*((temp(i,:)-3.9863).^2)).*1000; end
This seems to work fine, but as I have such a large dataset it takes a long time to run. Is there a way of doing this calculation without having to use a loop?
thanks

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 5 de Nov. de 2011
e.g.
temp = randi(40,5)
rho2=(1-((temp+288.9414)./(508929.2*(temp+68.12963))).*((temp-3.9863).^2))*1000
  1 comentario
ricco
ricco el 5 de Nov. de 2011
Didn't realise it was that simple, thank you very much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by