필터 지우기
필터 지우기

loops

조회 수: 3 (최근 30일)
ricco
ricco 2011년 11월 5일
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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 11월 5일
e.g.
temp = randi(40,5)
rho2=(1-((temp+288.9414)./(508929.2*(temp+68.12963))).*((temp-3.9863).^2))*1000
  댓글 수: 1
ricco
ricco 2011년 11월 5일
Didn't realise it was that simple, thank you very much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by