Consecutive subtraction of the entries of a vector

8 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(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