use Tic Toc for function
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2019-7-9
You cannot time an individual component of a cellfun.
timeit(@() test(A{index}), 0)
采纳的回答
Bjorn Gustavsson
2019-7-8
Either scrap cellfun and loop over the elements of A, or plug tic-toc into your test-function.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!