Finding absolute difference between each row of a tall array
조회 수: 6 (최근 30일)
이전 댓글 표시
I am trying to find sum of absolute differences of each row. So if the input matrix A is M x N, the output matrix B should be M x M and
B( i , j ) = sum(abs( A ( i , : ) - A ( j , : ))). For small matrices the below two codes work.
lng=size(A,1);
B=reshape(sum(abs(repelem(A,lng,1)-repmat(A,lng,1)),2),lng,lng);
OR
lng=size(A,1); wdt=size(A,2);
B=zeros(lng);
for i=1:wdt
B=B+abs((A(:,i)-A(:,i)'));
end
The problem is that A is a tall matrix with dimension M larger than N. Thus, I cannot apply neither of these two methods on it. For the first code, it doesn't allow me to give the first inputs of repelem and repmat commands something different than 1. For the second code, taking the transpose fails for the tall array (is that forbidden totally for tall arrays or is there a workaround?) . Can someone please help me on this? I would appreciate if it would be a vectorized code.
Thanks in advance.
댓글 수: 1
madhan ravi
2018년 12월 24일
편집: madhan ravi
2018년 12월 24일
probably Edric Ellis can share some light , he is really an expert on this (tall arrays)..
답변 (1개)
Cris LaPierre
2018년 12월 24일
I would use the diff function.
I would probably use abs(diff()).
There is a note on the limitations for diff with tall arrays:
- You must use the three-input syntax Y = diff(X,N,dim).
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!