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
댓글 수: 0
답변 (1개)
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) ;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Octave에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!