How to add last element of vector to next vector
2 ビュー (過去 30 日間)
古いコメントを表示
Consider a vector A= [1 2 3 4 5] and another vector B=[ 10 11 17 22 24]
Now what i want to do is that last element of A i.e. A(end) which in this case is 5 shall be added to the first element of B i.e. B(1 ) which in this case is 10. The result which is 15 shall be placed in any other vector or in A as A=[ 1 2 3 4 5 15]. Uptill now its easy. Now the difficult part where I am stuck. the difference of successive elements after neglecting first element of B is any vector C= [ 6 5 2].
Now I want to form a vector D (or the same vector A can be modified) in the following form [1 2 3 4 5 15 21 26 28] i.e. last element of A is added with the first element of C and is given a position in A at the end. Again this newly added number is placed at the end of A and is added with C(2) element i.e. 5 and added at the end position of A and so on.
Can any one please help?
0 件のコメント
回答 (1 件)
Ameer Hamza
2020 年 10 月 14 日
Try this
A = [1 2 3 4 5];
B = [ 10 11 17 22 24];
D = [A A(end)+B(1)];
D = [D cumsum(diff(B(2:end)))+D(end)];
4 件のコメント
NAVNEET NAYAN
2020 年 10 月 14 日
Got it now. No you are not vague. I was not knowing the entire scenario.
参考
カテゴリ
Help Center および File Exchange で Verification, Validation, and Test についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!