Consecutive subtraction of the entries of a vector

조회 수: 11 (최근 30일)
Hmm!
Hmm! 2021년 1월 13일
댓글: James Tursa 2021년 1월 14일
I am a novist in MATLAB. I have no idea of how to subtract the entries of a vector consecutively. Say if A=[3,5,9,11,15]' and I want something like this B =[3, 2, 4, 2, 4]. Any help will do, thanks in advance.

채택된 답변

James Tursa
James Tursa 2021년 1월 13일
편집: James Tursa 2021년 1월 13일
If A is a row vector:
B = [A(1) diff(A)];
If A is a column vector:
B = [A(1);diff(A)];
  댓글 수: 3
Hmm!
Hmm! 2021년 1월 14일
A typo B = [A(1); A./ A]
James Tursa
James Tursa 2021년 1월 14일
B = [A(1);A(2:end)./A(1:end-1)];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by