필터 지우기
필터 지우기

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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by