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

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

-
Can you explain more clearly what you are looking for? The title doesn't match how A relates to B (the max element of A neither equals nor is in the same position as the min element of B). And the "going in the opposite direction" description doesn't fit A and B either, since A goes {up, down, down, up} and B goes {down, down, up, up}, so half the time they go opposite directions and half the time they are going the same direction. So what is it you are really looking for? It might help to describe what you need it for. – Matt Apr 27 '11 at 8:09
@Matt ok 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" – Rick T Apr 27 '11 at 8:49
So you have something like a triangular wave? – J. M. Apr 27 '11 at 8:54
Do you want B to be the same as A but shifted by 1/4 period? – Matt Apr 27 '11 at 9:49
A good website to find a formula for a sequence is The On-Line Encyclopedia of Integer Sequences http://oeis.org/ – Rick T Apr 29 '11 at 11:00

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

-