Computing a time it takes for matlab to complete a nest of for loops?

조회 수: 2 (최근 30일)
Andy
Andy 2013년 2월 19일
I'm trying to calculate the time it takes for matlab to complete three nests of for loops each going from 1 to a hundred. I used cputime to calculate the time. Problem is, the time increases in each trial I make. My code goes like this:
t=cputime;
for i = 1:100
for j = 1:100
for k = 1:100
end
end
end
t
Nothing should be running in the loop. I am required to just take the time it takes for matlab to go through all of the loops.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 19일
편집: Azzi Abdelmalek 2013년 2월 19일
Use tic toc
tic
for i = 1:100
for j = 1:100
for k = 1:100
end
end
end
tim=toc
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 19일
When you say nothing should be running in the loop, it's false, the incrementation inside a loop can't be done without Matlab running!

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

카테고리

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