own diff() function: Y= X2 - X1.....Xn+1-Xn
own diff() function: Y= X2 - X1.....Xn+1-Xn
(OP)
Hello,
is there anybody who knows how to change the matlab included diff() function to the following form:
own diff() function: Y= X2 - X1.....Xn+1-Xn
I just have created an m File where I do this manually seperate from diff() like:
for(c=1:1:length(x)-1)
Y(c)=[(x(c)-x(c+1))];
end
The sample code above takes a lot of time. For my data file (including 1,750,000 values)it takes about 10 hours. The matlabs own diff takes a piece of this time. Hope you can understand my request in this matter.
Thanks in advance.
PsyDelic
is there anybody who knows how to change the matlab included diff() function to the following form:
own diff() function: Y= X2 - X1.....Xn+1-Xn
I just have created an m File where I do this manually seperate from diff() like:
for(c=1:1:length(x)-1)
Y(c)=[(x(c)-x(c+1))];
end
The sample code above takes a lot of time. For my data file (including 1,750,000 values)it takes about 10 hours. The matlabs own diff takes a piece of this time. Hope you can understand my request in this matter.
Thanks in advance.
PsyDelic





RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
TTFN
RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
His profile only shows one posting to Eng-Tips
TTFN
RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
As stated in the MATLAB help files preallocation significantly improves throughput.
CODE
tic
A=zeros(dirsize,2);
Z=zeros(dirsize,1);
for i = 1:dirsize
A(i,1)=dirsize+1-i;
A(i,2)=i^2;
end
B=sortrows(A,1);
for i = 1:dirsize
Z(i)=B(i,2);
end
C=diff(Z);
toc
t=toc
takes 2.4 seconds on a 1.8 GHz P4 with 512MB of memory.
The code creates a 2 column matrix, using the first column as a reverse index, data in the second column. The matrix is sorted, the second column is extracted and diff() is applied to the resultant vector.
TTFN
RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
for (c=length(x):1:1)
y=diff(x(c)-x(c+1));
end
Thank you very much for your help!
Bye
RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
This is the one-stop shop for Matlab duscussions - a USENET group that's been alive since c. 1993. All the experts reside there. Sometimes engineering questions stray here too. Othertimes there's the boring cross-posting activity.
RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
RE: own diff() function: Y= X2 - X1.....Xn+1-Xn
-diff(x)