a=rand(100,100);
tic
[b,pos]=sort(a(:,1));
aa=a(pos,:);
toc
A=sortrows(a,1);
det(aa-A)
前面的演算法時間要短,效果是一樣的
Elapsedtimeis0.000110seconds.
Elapsedtimeis0.000259seconds.
ans=
0
用個小矩陣檢測下
a=magic(5);
aa=a(pos,:)
A=sortrows(a,1)
a=
17241815
23571416
46132022
101219213
11182529
aa=
Elapsedtimeis0.000133seconds.
A=
Elapsedtimeis0.000223seconds.
a=rand(100,100);
tic
[b,pos]=sort(a(:,1));
aa=a(pos,:);
toc
tic
A=sortrows(a,1);
toc
det(aa-A)
前面的演算法時間要短,效果是一樣的
Elapsedtimeis0.000110seconds.
Elapsedtimeis0.000259seconds.
ans=
0
用個小矩陣檢測下
a=magic(5);
tic
[b,pos]=sort(a(:,1));
aa=a(pos,:)
toc
tic
A=sortrows(a,1)
toc
det(aa-A)
a=
17241815
23571416
46132022
101219213
11182529
aa=
46132022
101219213
11182529
17241815
23571416
Elapsedtimeis0.000133seconds.
A=
46132022
101219213
11182529
17241815
23571416
Elapsedtimeis0.000223seconds.
ans=
0