문제

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 (and A again for reference)

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]
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]

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

tia

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"

도움이 되었습니까?

해결책

Your title and description are very confusing, and I'm unable to tell from them what you are trying to do. However, looking at the desired output array B that you want to generate from your input array A, I can give you a couple of operations that will do that transformation for you:

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

This finds the absolute differences in values along array A, multiplies these differences by the sign of the elements of A (counting 0 as positive by adding EPS to the signal), takes the cumulative sum of these values, then subtracts them from the maximum value in A.

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]);

다른 팁

Rick,

Is it as simple as B[i] = 1 - abs(A[i]) ... or am I missing something?

The negatives soon stop lining up, which makes it difficult to see the relationship.

Cheers. Keith.


EDIT: Nope, it's not that simple!

There is no "ordinary computation" which will produce these results.

It's all good untill we get upto .1 0 -.1 ... which produces -.9 -1 -.9

I guess you'd have to "walk through it" by 10's, swapping the sign of the result after each 10.

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=[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]

Does that make ANY sense? You can see why I didn't do Higher Level maths.

Cheers. Keith.

Does the following code does more or less what you want?

Ad = diff(A);
B = cumsum([max(A) -Ad]);

This will also create the correct answer

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top