필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

decrease the time of calculating

조회 수: 1 (최근 30일)
fatema saba
fatema saba 2015년 11월 4일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi I want to decrease the time of calculating in my algorithm. in this algorithm there is an objective function.in every iteration x is achieved from main loop of algorithm then it is entered to objective function in order to calculate the value of objective function. x is a matrix with 1000 rows and 1000 columns and 4 in third dimension. it is (0-1)matrix. also there is the other matrix (c). this matrix has the same rows, columns and third dimension with values between (1-256).this matrix is constant in every iteration.
this is my code:
z=sum(sum(sum(c.*x)))
the function is very simple but why it takes many times to calculate in every iteration.

답변 (1개)

Jan
Jan 2015년 11월 4일
편집: Jan 2015년 11월 4일
Try:
L = (x == 1); % Convert it to a logical array outside the loops
...
z = sum(c(L))
To my surprise logical indexing was not implemented efficiently - at least in former Matlab versions. So you can give this a try: FEX: CopyMask
z = sum(CopyMask(c, L));

이 질문은 마감되었습니다.

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by