假设我在Matlab中获得两个函数的执行时间,我有一个循环来获得不同的测量值:
for i = 0: 100
Start1 = tic;
somefunction1;
Total1 = toc(Start1);
Start2 = tic;
somefunction2;
Total2 = toc(Start2);
end;
如何获得具有以下结果的mtarix:
iteration times1 times2
1 someval1 someval1
2 someval2 someval2
3 someval3 someval2
...
它们可以插入另一个矩阵吗?怎么样?
-----------------------------------修改 我已完成建议并且有效:
N = 100;
Total = zeros(N,2);
for i = 1: N
Start1 = tic;
%somefun1
Total(i,1) = toc(Start1);
Start2 = tic;
%somefun2
Total(i,2) = toc(Start2);
end;
答案 0 :(得分:2)
将Total1和Total2合并为一个矩阵。
N = 100;
Total = zeros(N,2);
...
Total(i,1) = toc(Start1);
...
Total(i,2) = toc(Start2);
我会将迭代作为一个单独的向量:
iteration = 1:N;
然后您可以绘制结果,例如:
plot(iteration,Total)