how can I increase the performance of this loop?
이전 댓글 표시
nPts = 15;
a = linspace(0.1, 2.0, nPts);
b = linspace(0.1, 2.0, nPts);
c = linspace(0.1, 2.0, nPts);
d = linspace(-0.3, 2.0, nPts);
e = linspace(-0.3, 2.0, nPts);
f = linspace(-0.3, 2.0, nPts);
res = zeros(length(a)*length(b)*length(c)*length(d)*length(e)*length(f), 2);
idx = 1;
for i=a
for j=b
for k=c
for l=d
for m=e
for n=f
C = [i l m; l j n; m n k];
% do somthing with C and store a row in "res"
detF = sqrt(det(C));
if detF<0.001
res(idx,:)=NaN;
else
Cbb = detF^(-2/3).*C;
res(idx, 1) = trace(Cbb);
res(idx, 2) = trace(inv(Cbb));
end
% increment counter
idx = idx +1 ;
end
end
end
end
end
end
%remove the rows with NaN's
The above code works, but is probably not a good implementation.
How can I increase the performance of this code? My objective is to build all combinations of the elements in the vectors a,b,c,d,e,f , then built a symmetric matrix for each combination as shown, compute the first two principal invariants of the (scaled matrix), and store it in a result variable and visualize it finally in a scatter plot.
댓글 수: 2
Stephen23
2023년 7월 11일
"How can I increase the performance of this code?"
Perhaps by changing the part labeled 'do somthing with C and store a row in "res" so that it can process arrays:
or rewriting it using more efficient code practices:
Or perhaps by using parallel processing, or lots of other ways... without knowing the details of what that "somthing" is, we can't do much more for you.
SA-W
2023년 7월 11일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!