Divide consecutive numbers and put them in a table

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

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by