How to make a function that calculates percentage change in a vector

25 次查看(过去 30 天)
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

回答(1 个)

KSSV
KSSV 2020-4-3
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) ;

类别

Help CenterFile Exchange 中查找有关 Octave 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by