How to make a function that calculates percentage change in a vector
26 views (last 30 days)
Show older comments
i have a document called gdp.csv which contains a vertical vector of values. How would I make a script that returns the percentage change between every subsequent value?
x=csvread('gdp.csv')
for i=0; i++; i == length(x)-1
p = (x(i+1)-x(i))/(x(i))
endfor
0 Comments
Answers (1)
KSSV
on 3 Apr 2020
Loop:
x=csvread('gdp.csv')
for i=1:length(x)-1
p = (x(i+1)-x(i))/(x(i))
end
Vector:
p = diff(x)./x(1:end-1) ;
0 Comments
See Also
Categories
Find more on Octave in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!