How can I use the Xcorr function for two matrix operation! I want to use this for gpuArray.

조회 수: 3 (최근 30일)
my code as follows
s1; %this is a matrix for 512*403;
s2; %this is a matrix for 512*403;
for i = 1:512
[acor lag] = xcorr(s1(i,:),s2(i,:));
end
I want to use the gpuArray for this, and I don't want to use the for loop, how can I do this.

답변 (1개)

Ridwan Alam
Ridwan Alam 2019년 11월 25일
편집: Ridwan Alam 2019년 11월 25일
The operation (xcorr) inside the for loop is not a matrix operation, rather an operation between two vectors (corresponding rows of two matrices). I don't think you can skip the for loop unfortunately.
Other than that,
S1 = gpuArray(s1);
S2 = gpuArray(s2);
acor = [];
for i = 1:512
[acori,lag(i)] = xcorr(S1(i,:),S2(i,:));
acor(i,:) = gather(acori);
end
  댓글 수: 2
ang lee
ang lee 2019년 11월 25일
Do you think I can rewrite the xcorr function so that it can perform matrix operations, because I think parallel operations without the for loop will be faster.
Ridwan Alam
Ridwan Alam 2019년 11월 25일
편집: Ridwan Alam 2019년 12월 3일
that's indeed a good idea. specially if you transpose the second matrix, it should have a syntax similar to matrix multiplication. good luck, and please keep us informed. also, if it works, please accept the response as an answer. thanks.

댓글을 달려면 로그인하십시오.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by