Login  Register

Re: Subtract consecutive values in an array

Posted by Straub, Volko A. (Dr.) on Oct 21, 2016; 5:09am
URL: http://imagej.273.s1.nabble.com/Subtract-consecutive-values-in-an-array-tp5017426p5017442.html

Hi Jens,

On 20/10/2016 13:06, jens rietdorf wrote:
> Hi Volko,
>
> how about converting the array into an image, duplicate it, add one pixel
> to each copy at beginning/end and subtract the images?
Thanks for the suggestion - that is definitely an option and I will give
it a go.
Volko

>
> Abraços, Jens
>
> Dr. Jens Rietdorf, visiting scientist @ center for technological
> development in health CDTS, Oswaldo Cruz Foundation Fiocruz, Rio de Janeiro
> Brasil.
>
> On Thu, Oct 20, 2016 at 5:12 AM, Volko Straub <[hidden email]> wrote:
>
>> Dear All,
>>
>> Is there a simple method in a macro to subtract the first value in an
>> array from the second value, etc? This could obviously done by writing a
>> for-loop and iterating through the array, but that seems to be a bit
>> clumsy. Is there a more elegant way that I am missing?
>>
>> Here is what I try to achieve:
>> Let's assume, I have the following array [6,9,4,3,5,...]. I would like to
>> calculate an array that contains the difference between consecutive
>> elements in the original array, i.e. [3,-5,-1,2, ...] or more generally
>> [x1-x0, x2-x1, x3-x2, ...]. Obviously the new array would need to be one
>> element shorter than the original array as there is nothing to subtract
>> from x0.
>>
>> Perhaps this could be achieved by shifting all elements in an array by one
>> index position and then subtract the original array from the shifted array,
>> but I don't seem to work out whether this is possible within a macro.
>>
>> Any suggestions/pointers would be very welcome.
>> Thanks,
>> Volko
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html