How to add last element of vector to next vector
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Ameer Hamza
am 14 Okt. 2020
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 Kommentare
NAVNEET NAYAN
am 14 Okt. 2020
Got it now. No you are not vague. I was not knowing the entire scenario.
Siehe auch
Kategorien
Mehr zu Verification, Validation, and Test finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!