Divide consecutive numbers and put them in a table

5 views (last 30 days)
TotalReturnIndexLevel
_____________________
12/31/2019 100
1/31/2020 90.3
2/28/2020 104.75
3/31/2020 115.01
4/30/2020 123.18
5/31/2020 139.81
6/30/2020 131.28
7/31/2020 137.71
8/31/2020 145.56
How can I divide consecutive numbers and put them in a table.
For example
90.3/100 = 0.903
104.75/90.3 = 1.16
But make it automatic for a long list and put the outcomes in a table

Answers (1)

Image Analyst
Image Analyst on 19 Feb 2022
Edited: Image Analyst on 19 Feb 2022
Assuming v is your vector of numbers
ratios = v(2:end) ./ v(1:end-1)
% Create table
t = table(ratios(:), 'VariableNames', {'Ratios'})

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!