MatLab函数将点从最大或最小点向左或向右移动 [英] MatLab function that shifts points to the left or right from a max or minimum point
问题描述
我试图找出一个函数,该函数将在matlab数组中找到一个与我设置的最小值和最大值相差x点数的点.
I'm trying to figure out how to have a function that will find a point that is x number of points away from my set min and max in an array in matlab.
让我们说我做max(data(row 1:row 2,column))
,这给了我一个要点.我想在该值的左边和右边找到与4点相对应的值.
Lets say that I do max(data(row 1:row 2,column))
and it gives me a point. I want to find the value that corresponds to 4 points to the left, and to the right of this value.
所以可以说,它告诉我第5列的最大值为1.5,并且位于第5行 我将如何使该函数向后移动4行/点?
So lets say it tells me that the max of column 5 is 1.5 and it is located in row number 5 How would I make the function move it 4 rows/points backwards?
示例:
max(data_10MIN(49000:51000,9)
ans = -3.5226
data_10MIN(50251) = -3.5226
,所以我只知道向后4个点是50247
,而向前移动4个点将是50255
,但是我将如何为我做一个函数呢?因为max(data_10MIN(49000:51000,9)
作为函数不能提供x
和y
值.
data_10MIN(50251) = -3.5226
, so I would just know that 4 points backwards is 50247
, and moving 4 points forwards would be 50255
but how would I have a function do this for me? since max(data_10MIN(49000:51000,9)
as a function does not give me the x
and y
values.
推荐答案
max 函数还会返回最大值的(首次出现)索引.您可以简单地偏移该值,并在左侧/右侧获得所需的4点.
The max function also returns the (first occurence) index of the maximum value. You can simply offset that value and get to your desired 4 points to the left/right.
[maxvalue, idx] = max(data);
left4idx = max(1, idx - 4);
right4idx = min(numel(data), idx+4);
left4_value = data(left4idx);
right4_value = data(right4idx);
(在向索引添加/减去时添加边界检查是个好主意,在这里我使用min/max函数进行了此操作.)
(It is a good idea to add a boundary check when adding/subtracting to an index, here I did that using the min/max functions.)
这篇关于MatLab函数将点从最大或最小点向左或向右移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!