Find the difference between non-zero elements

조회 수: 5 (최근 30일)
Steven Ross
Steven Ross 2014년 3월 22일
편집: Jan 2014년 3월 22일
I am trying to determine the differences between the non zero values in the data attached. I have achieved this using the code below
xdiff = diff(xdup(xdup~=0));
This provides a new array of size (27 x 1 double)
However I would like to map the new delta values to the original array (xdup)by including the original zero values. I understand the new array will be (47 x 1 double) compared to xdup (48 x 1 double. Please see xdiff in the data set as an example of what I want to achieve.
I hope this makes sense?
  댓글 수: 4
Jan
Jan 2014년 3월 22일
It would be useful, if you offer the data in a more convenient way than an XLSX file.
Steven Ross
Steven Ross 2014년 3월 22일
편집: Jan 2014년 3월 22일
Original data [EDITED, Jan, this allows a copy&paste now:]
xdup = [1.85E-05
0
0
0
0
0
0
0
0
0
0
1.82E-05
0
1.79E-05
0
1.76E-05
1.74E-05
0
1.71E-05
1.68E-05
0
1.65E-05
1.62E-05
1.59E-05
1.56E-05
1.53E-05
1.50E-05
1.44E-05
1.41E-05
1.35E-05
1.32E-05
1.26E-05
1.24E-05
1.18E-05
1.15E-05
1.12E-05
1.06E-05
1.03E-05
0
1.00E-05
9.71E-06
0
9.41E-06
0
0
0
0
9.12E-06]
How the data is returned
xdiff no zeros -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -5.88E-07 -2.94E-07 -5.88E-07 -2.94E-07 -5.88E-07 -2.94E-07 -5.88E-07 -2.94E-07 -2.94E-07 -5.88E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07
How I would like to have the data
xdiff -2.94E-07 0 0 0 0 0 0 0 0 0 0 -2.94E-07 0 -2.94E-07 0 -2.94E-07 -2.94E-07 0 -2.94E-07 -2.94E-07 0 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -2.94E-07 -5.88E-07 -2.94E-07 -5.88E-07 -2.94E-07 -5.88E-07 -2.94E-07 -5.88E-07 -2.94E-07 -2.94E-07 -5.88E-07 -2.94E-07 -2.94E-07 0 -2.94E-07 -2.94E-07 0 -2.94E-07 0 0 0 0

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2014년 3월 22일
편집: Jan 2014년 3월 22일
What about this:
index = (xdup ~= 0);
result(index) = [diff(xdup(index)); 0];
Now you have to crop the last element of the result.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by