From: mb b on
Hello guys, I can not figure out how to make a for loop for a m-by-1 matrix (hence a 1 column vector) with which I start at the second element and subtract the previous element and then repeat this operation on the following elements.
How can I do this ?

for example I have an excel column called "Ref" that is made by these numbers:

Ref
839825
851892
851955
851969
851964
851518
851953
850544

I need something that in matlab will do for me :

851892-839825 =
851955-851892 =

ecc...
and create another column called :

Ref(j) - Ref(j-1)wih under it all the calcutated subtractions

Any help please ?
Thnak you
From: Matt Fig on
Would it make a DIFFerence if I told you that MATLAB has a builtin function to do just what you want?
From: Jan Simon on
Dear Marco!

> Hello guys, I can not figure out how to make a for loop for a m-by-1 matrix (hence a 1 column vector) with which I start at the second element and subtract the previous element and then repeat this operation on the following elements.
> How can I do this ?
>
> for example I have an excel column called "Ref" that is made by these numbers:
>
> Ref
> 839825
> 851892
> 851955
> 851969
> 851964
> 851518
> 851953
> 850544
>
> I need something that in matlab will do for me :
>
> 851892-839825 =
> 851955-851892 =
>
> ecc...
> and create another column called :
>
> Ref(j) - Ref(j-1) wih under it all the calcutated subtractions

What have you tried so far? Have you read the "Getting started" section of the documentation? Did you study "help for"?

Kind regards, Jan