use Tic Toc for function

조회 수: 3 (최근 30일)
NA
NA 2019년 7월 8일
댓글: Walter Roberson 2019년 7월 9일
I want to calculate simulation time of only bigest length of A.
A={[1,2],[1,2,4,5,6,7],[4,8,2],[1,3,5,7]}
[~,index] = max(cellfun(@length,A)); % find index of maximum length
%
tic1 = tic;
[B]=cellfun(@(s)test(s),A )
elapsedTime = toc(tic1);
function[B]=test(A) %function
B=A+1
end
I want to calculate simulation time of A{index}.
I do not know how to use tic toc for this matter.
  댓글 수: 4
NA
NA 2019년 7월 8일
편집: NA 2019년 7월 8일
Thank you. I want to accept your answer (Walter Roberson), but you should answer it below.
If I want to use timeit(), this code have problem,
[B]=cellfun(@(s)test(s),A )
timeit([B{index}])
Walter Roberson
Walter Roberson 2019년 7월 9일
You cannot time an individual component of a cellfun.
timeit(@() test(A{index}), 0)

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

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2019년 7월 8일
Either scrap cellfun and loop over the elements of A, or plug tic-toc into your test-function.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by