How to vectorize double sum

5 ビュー (過去 30 日間)
Esegboria Osarhemen
Esegboria Osarhemen 2019 年 2 月 9 日
Please how can i vectorize this double sum
N=4
x=randn(3,N);
for i=1:N-1
for j=2:N
if j>i
a=x(:,i)-x(:,j)
end
end
end

採用された回答

Stephen23
Stephen23 2019 年 2 月 9 日
編集済み: Stephen23 2019 年 2 月 9 日
>> N = 4;
>> x = randi(9,3,N)
x =
5 4 8 9
2 9 9 8
1 1 4 1
>> F = @(c)bsxfun(@minus,x(:,c),x(:,c+1:N));
>> M = cell2mat(arrayfun(F,1:N-1,'uni',0))
M =
1 -3 -4 -4 -5 -1
-7 -7 -6 0 1 1
0 -3 0 -3 0 3
  1 件のコメント
Esegboria Osarhemen
Esegboria Osarhemen 2019 年 2 月 9 日
Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by