0
$\begingroup$

Greetings all

logic for adjusting max number in array to min number in second array

I have an array "A"

A=[0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 .9 .8 .7 .6 .5 .4 .3 .2 .1 0 -.1 -.2 -.3 -.4 -.5 -.6 -.7 -.8 -.9 -1 -.9 -.8 -.7 -.6 -.5 -.4 -.3 -.2 -.1] 

And I want the second array to be going in the "opposite" direction so when the numbers are going high in array "A" the numbers in array "B" should be going low

example of what array "B" should look like

B=[1 .9 .8 .7 .6 .5 .4 .3 .2 .1 0 -.1 -.2 -.3 -.4 -.5 -.6 -.7 -.8 -.9 -1 -.9 -.8 -.7 -.6 -.5 -.4 -.3 -.2 -.1 0 .1 .2 .3 .4 .5 .6 .7 .8 .9] 

I tried using this logic but it makes everything positive of course

arrayB=-abs(arrayA).+abs(max(arrayA)); 

but that didn't work I'm using matlab but if someone knows the correct logic I can convert it over the matlab syntax

The numbers represent different amplitudes of a signal so when the amplitude of one signal arrayA is going up the other signal arrayB should be going down. There is "overlap"

tia

  • 0
    A good website to find a formula for a sequence is The On-Line Encyclopedia of Integer Sequences [http://oeis.org/](http://oeis.org/)2011-04-29

1 Answers 1

0

To answer this here are some ways to do this

1st) way

A=[0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 .9 .8 .7 .6 .5 .4 .3 .2 .1 0 -.1 -.2 -.3 -.4 -.5 -.6 -.7 -.8 -.9 -1 -.9 -.8 -.7 -.6 -.5 -.4 -.3 -.2 -.1]';  B=circshift(A,30) 

2nd) way

B = max(A)-cumsum([0 abs(diff(A))].*sign(A+eps)); 

3rd) way Another solution in this case is simply to create a circular shift of A using array indexing. For example, shifting the array A such that its maximum value is at the beginning of the array will give you the desired array B:

[~,maxIndex] = max(A); B = A([maxIndex:end 1:maxIndex-1]); 

thanks goes to gnovice for his/his help