Find the difference between non-zero elements

4 visualizaciones (últimos 30 días)
Steven Ross
Steven Ross el 22 de Mzo. de 2014
Editada: Jan el 22 de Mzo. de 2014
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 comentarios
Jan
Jan el 22 de Mzo. de 2014
It would be useful, if you offer the data in a more convenient way than an XLSX file.
Steven Ross
Steven Ross el 22 de Mzo. de 2014
Editada: Jan el 22 de Mzo. de 2014
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

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 22 de Mzo. de 2014
Editada: Jan el 22 de Mzo. de 2014
What about this:
index = (xdup ~= 0);
result(index) = [diff(xdup(index)); 0];
Now you have to crop the last element of the result.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by