From: andrea182 on
thanks...
From: Jan Simon on
Dear Andrea

> open contains a matrix 99*1
>
> i want to create a matrix call derivato where the element number 1 is the subtract of the first with the second element of the vector open ...the element number 2 is the subtract of the the second with the third element...ecc...
>
> function deriva(open)
> for prova=1:(length(open)-1)
> derivato(prova,1)=open(prova,1)-open(prova+1,1);
> end
>
> but it produce me a mistake...where is the error???

A general advice:
It is not getting clear what "producing a mistake" means. If an error message appear, copy it and show the corresponding line here.
If the calculated values do not match your expectations, show us the input value, the output value and your expectation.

I do not see an error in your function.
Beside the really efficient DIFF, you can calculate the difference vectorized also: Just move the index vector from the FOR loop inside the calculations:
function deriva(open)
derivato = open(1:(length(open) - 1)) - open(2:length(open));
return;
This method can be easily applied to other calculations also, e.g. addition or division.

Good luck and have fun with Matlab, Jan
First  |  Prev  | 
Pages: 1 2 3
Prev: How use datcomimport
Next: How can plot signal by cwt?