Prev: How use datcomimport
Next: How can plot signal by cwt?
From: andrea182 on 29 Nov 2009 19:04 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??? thanks a lot
From: ImageAnalyst on 29 Nov 2009 19:10 Why not just use the built-in diff() function?
From: andrea182 on 29 Nov 2009 19:17 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <2783dc73-f95d-419a-b024-9c6af9e60652(a)j14g2000yqm.googlegroups.com>... > Why not just use the built-in diff() function? how can i do??? please it is so seample but i can't found the mistake...maybe is wrong open(prova,1) and i should chang this i don't know...
From: ImageAnalyst on 29 Nov 2009 19:32 You mean like this: % Generate vectors of sample data. vector1 = randperm(10) % Subtract element i from element (i+1). diffVector1 = diff(vector1) % Subtract element (i+1) from element i. % Note it's the same except a minus sign was added. % This is what Andrea wants. diffVector2 = -diff(vector1)
From: ImageAnalyst on 29 Nov 2009 19:39
If you really want to do it your way, then do this: (Basically get rid of the ",1" since you apparently have a 1D vecotr not a 2D array, and add a return (output) argument. I also changed the input arg name from open (a reserved keyword) to inputVector. function test clc; close all; clear all; workspace; % Generate vectors of sample data. vector1 = randperm(10) % Subtract element (i+1) from element i. % This is what Andrea wants. diffVector2 = deriva(vector1) function derivato = deriva(inputVector) for prova = 1 : (length(inputVector)-1) derivato(inputVector) = inputVector(prova) - inputVector(prova +1); end |