Difference Calculation between current value and a specified prior value

1 view (last 30 days)
Hello,
I use the following to calculate percentage change:
B = (diff(VMA)./(VMA(1:end-1))*100;
What this does is (x1 - x2) / x2....
How can i make it where i pick the prior value, for example i want the rate of change but looking back 10 values...therefore:
B = (x1 - x10) / x10
Thanks!

Answers (1)

David Hill
David Hill on 19 Jan 2022
Not sure exactly what you are after, an example would be helpful.
B=(x(1:10)-x(10:19))./x(10:19);
  1 Comment
IDN
IDN on 19 Jan 2022
Edited: IDN on 19 Jan 2022
Thanks for helping me out. I want this calculation be done for all my array.Example out put on original code:
VMA B
5.247743 0
5.7918 10.36745 = ((5.7918 - 5.247743)/5.247743)*100
6.1518 6.215684 = ((6.1518 - 5.7918)/5.7918)*100 and so on...
6.311829 2.601329
6.429629 1.866337
6.456114 0.411932
6.562157 1.642518
6.376371 -2.83117
6.187729 -2.95847
6.108229 -1.2848
6.107386 -0.0138
6.111971 0.075085
5.996186 -1.89441
5.778271 -3.63422
5.484386 -5.08605
5.324986 -2.90643
5.232614 -1.73468
5.097386 -2.58434
5.072029 -0.49745
5.118757 0.921299
5.323328 3.996504
what i would like its something like B = ((5.323328 - 5.232614)/5.232614)*100 = 1.73363 be able to change how many values back i want the difference and percentage change changed.

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!