How to compute relative change from starting to ending ?

 Accepted Answer

Jan
Jan on 21 Oct 2014
Edited: Jan on 21 Oct 2014
Let me guess:
x = rand(5, 1);
rel_change = diff(x) ./ x(1:length(x) - 1);
[EDITED] Or perhaps:
rel_change = (x - x(1)) ./ x;

More Answers (1)

rel_change = (x(end)-x(1))/x(1);

4 Comments

Hi, Thanks for the quick reply. But I think this answer takes the last and the first value of the record. let me clarify my question, I have a record of column which contains many logs. I would like to know the relative change from the start of the log to the end,not just considering the last and the first values. Any idea? Thanks,
Jan
Jan on 21 Oct 2014
Edited: Jan on 21 Oct 2014
Please, Abinet, clarify your question by editing the original text. Hiding important details in comments of answers is not optimal.
Notice that readers do not have the faintest idea, what a "record of column" is and "logs" cna mean different things also. "Relative change from the start to the end" is not exactly defined mathematically. Please post a short example of your data and the wanted result. A vector of 4 elements should be sufficient.
Sorry for making confusion, What I mean a record is the values in the column. In short, I am looking for a relative change computation of a single column which contains many values. for example: x= rand(2000,1) How to compute a relative change from staring point till the end?
Thanks!
Again: Please clarify the question by editing the original question. This is the place where readers expect and find all information. Comments disappear soon in the standard display, when further comments are posted.
Please do not use a random input and no output to define the mathematical meaning of your question. What do you expect for:
x = [1,3,-2,10]
? And please add this to the question above, not as an comment. Thanks.

Sign in to comment.

Categories

Find more on Parallel Computing in Help Center and File Exchange

Tags

Asked:

on 20 Oct 2014

Edited:

Jan
on 21 Oct 2014

Community Treasure Hunt

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

Start Hunting!