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

조회 수: 25 (최근 30일)
Bryan Zhang
Bryan Zhang 2020년 4월 3일
답변: KSSV 2020년 4월 3일
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