|
楼主 |
发表于 2009-1-6 11:05
|
显示全部楼层
三种方法的速度比较
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 方法一
clear;clc
tic % 测试开始
N=1024;
for k=1:N;
for j=1:N;
f(k,j)=k^2+j^2+1;
j=j+1;
end
k=k+1;
end
toc % 测运行时间
Elapsed time is 5.811530 seconds.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 方法二(快多了)
clear;clc
tic % 测试开始
N=1024;
nn=[1:N].^2;
mm=nn';
ff=repmat(mm,1,N)+repmat(nn,N,1)+ones(N);
toc %%%
Elapsed time is 0.047724 seconds.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 方法三
clear;clc
tic % 测试开始
N=1024;
f=zeros(N);
for k=1:N
for j=1:N
f(k,j)=k^2+j^2+1;
end
end
toc %
Elapsed time is 1.258142 seconds. |
评分
-
1
查看全部评分
-
|