Subtracting the next element on a vector? Basic
8 次查看(过去 30 天)
显示 更早的评论
If I have a vector with n elements, and want a new vector with the subtraction of the first by the second element, and continues...
For exemple: A = [20, 8, 4, 1] turns into B = [(20-8),(8-4),(4,1)]
I started something with
n = length(A);
for k = 1:n
....
but nothing I tried worked them.
Thanks.
0 个评论
采纳的回答
Jiro Doke
2011-2-9
A = [20, 8, 4, 1];
B = -diff(A);
2 个评论
Steven Lord
2021-1-14
Jayaram ram flagged this as "its working good sir...."
The intended purpose of flags is to alert the editors and/or the admins about spam or other content that's not appropriate for Answers. To comment on the solution please use a comment like I'm doing here. Thanks.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!