简体   繁体   中英

Subtract value row by row in matlab

I have a 1 column matrix with the following values:

*-------*
|   6   |
|   4   |
|   3   |
|   1   |
|   1   |
*-------*

With this function, starting from the first value, I subtract the value in the following row and place 0 at the end. This is the result:

Delta = Ctv_ds_universal(1:(end-1),1)-Ctv_ds_universal(2:end,1);
Delta(end+1)=0;

*-----------*
|   2 (6-4) |
|   1 (4-3) |
|   2 (3-1) |
|   0 (1-1) |
|   0       |
*-----------*

Now, I would like to reverse the order and start subtracting from down to the top, placing 0 at the beginning. How can I modify the function?

*------------*
|    0       |
|   -2 (4-6) |
|   -1 (3-4) |
|   -2 (1-3) |
|    0 (1-1) |
*------------*
Delta = 0;
Delta = [Delta; Ctv_ds_universal(2:end,1)-Ctv_ds_universal(1:end-1,1)];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM