フィルターのクリア

How to vectorize this loop? Subsequental subtraction of columns within a matrix

1 回表示 (過去 30 日間)
I'm trying to vectorize the following loop:
a=rand(1000,100);
j=1;
k=2;
tic
for i=1:50;
b(:,i)=a(:,j)-a(:,k);
j=j+1;
k=k+1'
end
toc
Is there any easier way to subsequently subtract an entire column from the previous column within a matrix?
Thanks, Charles

採用された回答

the cyclist
the cyclist 2014 年 6 月 3 日
b = a(:,1:end-1) - a(:,2:end);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by