필터 지우기
필터 지우기

Fast sum and other functions in matlab?

조회 수: 6 (최근 30일)
Matlab_user
Matlab_user 2016년 8월 12일
편집: John D'Errico 2016년 8월 13일
Hi. I have very large matrices and they cost a lot to sum up or do any other basic calculation. Can anyone please recommend faster ways of doing basic matrix operations?
Example of a few very expensive lines of code that I have (matrices img, A, and B are very big, and img is a UHD image):
A = img(s_row:end_row, s_col:end_col);
C = sum(sum(abs(A))) / max(max(abs(B)));
E(s_row:end_row, s_col:end_col) = (1 - (const1 / C)) * D .* const2;

답변 (1개)

John D'Errico
John D'Errico 2016년 8월 13일
편집: John D'Errico 2016년 8월 13일
So, you think if they had faster ways to do something as common as a sum, they would not implement it? Nope, only slow code provided. :)
One minor enhancement. This may be slightly faster than a fragment you have written.
sum(abs(A(:)))/max(abs(B(:)))
I doubt it is much of a speed bump though.
You can look into using tools like your GPU to do some problems faster. (Which needs a separate tool.) Or, if you are doing a lot of these, the parallel computing TB may help. Speed does not come easily, and often, not cheaply.
Better is often to look more carefully at WHY you are doing those computations, and see if there is a better way.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by