取得のコードは、画像ごとにわずかに異なる場合があります。実行時間をよりよく理解するには、Matlab のプロファイリング ツールを使用することをお勧めします。
profile clear;
profile on;
% your code here
profile off;
profile viewer;
プロファイラーを使用すると、コードで何が時間がかかるかを確認できます。
さらに、コード スニペットでtoc
2 回呼び出すと、発生している奇妙な動作が発生する可能性があります。
より具体的な対策については、試してみてください
rTimes = zeros(1, numMethods);
% prepare images and what ever you need ...
for imi = 1:numImages
% read test image ...
tic;
% use your method for ret.
rTimes(1) = rTimes(1) + toc; % add this run time to your counter
tic;
% here you run method 2 that you want to compare to...
rTimes(2) = rTimes(2) + toc; % add run time for method 2
% do the same for all methods ...
tic;
% run the numMethods-th method
rTimes(numMethods) = rTimes(numMethods) + toc;
end
% now rTimes hold the running times (overall) for all methods over all test images.