Find the difference between non-zero elements
显示 更早的评论
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 个评论
Image Analyst
2014-3-22
What do you mean by "map"?
And for each pair of elements, the kth and the (k+1)st, which of those two elements do you want to be associated with the difference between them, the upper one or the lower one? Realize that if xdiff(k) is associated with xdup(k) and xdup(k+1) then it cannot be associated with the difference between xdup(k-1) and xdup(k). You'd need two difference arrays for that.
Steven Ross
2014-3-22
编辑:Steven Ross
2014-3-22
Jan
2014-3-22
It would be useful, if you offer the data in a more convenient way than an XLSX file.
Steven Ross
2014-3-22
编辑:Jan
2014-3-22
回答(1 个)
What about this:
index = (xdup ~= 0);
result(index) = [diff(xdup(index)); 0];
Now you have to crop the last element of the result.
类别
在 帮助中心 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!