将数组中的最大数量调整为第二个数组中的最小数量的逻辑

发布于 2024-11-03 07:13:25 字数 848 浏览 5 评论 0 原文

问候所有

将数组中的最大数调整为第二个数组中的最小数的逻辑

我有一个数组“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]

并且我希望第二个数组朝“相反”方向移动,因此当数组“A”中的数字变高时数组“B”中的数字应该变低

数组“B”应该是什么样子的示例(再次作为参考)

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]

我尝试使用这个逻辑,但它当然使一切都积极,

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

但这不起作用我正在使用matlab但如果有人知道正确的逻辑我可以转换它在 matlab 语法

tia

中,数字代表信号的不同幅度,因此当一个信号数组 A 的幅度上升时,另一个信号数组 B 的幅度应该下降。存在“重叠”

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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

沫尐诺 2024-11-10 07:13:25

您的标题和描述非常令人困惑,我无法从中看出您想要做什么。但是,查看您想要从输入数组 A 生成的所需输出数组 B,我可以为您提供一些操作将为您进行转换:

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

这会找到绝对 数组 A 中值的差异,将这些差异相乘通过 A 元素的 符号 (通过添加将 0 计为正数EPS 到信号),采用 这些值的累积和,然后从 A 中的最大值

这种情况下的另一个解决方案是使用 A 的循环移位="nofollow">数组索引。例如,移动数组 A 使其最大值位于数组的开头,将得到所需的数组 B

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

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]);
┾廆蒐ゝ 2024-11-10 07:13:25

Rick,

是不是像 B[i] = 1 - abs(A[i]) 一样简单……还是我遗漏了一些东西?

负面因素很快就会停止排列,这使得人们很难看出其中的关系。

干杯。基思.


编辑:不,事情没那么简单!

没有“普通计算”可以产生这些结果。

一切都很好,直到我们达到 .1 0 -.1 ...,它产生 -.9 -1 -.9

我猜你必须“走过它”以 10 为单位,每 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]

这有什么意义吗?你可以明白为什么我没有做高级数学。

干杯。基思.

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.

余生再见 2024-11-10 07:13:25

下面的代码或多或少符合您的要求吗?

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

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

Ad = diff(A);
B = cumsum([max(A) -Ad]);
马蹄踏│碎落叶 2024-11-10 07:13:25

这也将创建正确的答案

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文