Effacer les filtres
Effacer les filtres

loops

3 vues (au cours des 30 derniers jours)
ricco
ricco le 5 Nov 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

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by