MATLAB Answers

Finding absolute difference between each row of a tall array

61 ビュー (過去 30 日間)
Osman
Osman 2018 年 12 月 22 日
コメント済み: Osman 2018 年 12 月 24 日
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
madhan ravi 2018 年 12 月 24 日
probably Edric Ellis can share some light , he is really an expert on this (tall arrays)..

サインイン to comment.

回答 (1 件)

Cris LaPierre
Cris LaPierre 2018 年 12 月 24 日
I would use the diff function.
First, check that the function(s) you want to use are compatible with tall arrays. See this page.
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).

  1 件のコメント

Osman
Osman 2018 年 12 月 24 日
Unfortunately, diff does not work for me in this case. It only takes the difference between consecutive rows but I need the differences of a single row to all other rows of the matrix. Basically, I am trying to implement what pdist function does but it is not compatible with tall arrays. At the end, the code will be used for a knn Imputation method so if there is an easier way to apply it to tall arrays that will be really helpful. Still thanks for the advice :)

サインイン to comment.

サインイン してこの質問に回答します。


Translated by