我现在无法访问 matlab。但这里有一些步骤可以帮助您入门。请仔细检查您的测试用例的答案,以查看您获得所需的结果。
假设您有一个行向量x。在你的情况下说i你的数据矩阵的第 th 行,即x = data(i,:);
现在要找到(比如说)20% 变化的第一次出现,您可以使用:
cI = find( x >= x(1)*1.2, 1, 'first' );
其中cI将是第一个值变化大于 20% 的索引,并且x(cI)是所需值。
next 找到这个值使用后的最小值
[minV, minI] = min(x( (cI+1):end ));
并在此之后找到最大值:
[maxV, maxI] = max(x( (cI+minI+1):end ));
最后把所有东西放在一起:
[x(cI), minV, minI, maxV, maxI, (minI + maxI)]
这将适用于您的第一行。现在对于第三行,您需要确保cI有一个值。如果cI为空,则只需使用NaN(1,6).
如果cI+1或cI+minI+1超过元素的数量,将会有类似的错误检查。如果您正在寻找的更改发生得太晚,就会发生这种情况。
首先,您可以在每一行 ( ) 上设置一个for-loop i,但必须有更好的方法来矢量化代码。
整个设置为使用for-loop
% I have used generic variable names. Change them to something meaningful.
data = rand(500,360); % Use your data
change = 0.2; % or 20/100 if you prefer percentage
[nROWS, nCOLS] = size(data);
result = NaN( nROWS, 6); % Defining it this way saves the trouble to having to assign NaNs
for row = 1:nROWS
x = data( row, : ); % Not required, but easy to write code
cI = find( x >= x(1)*(1+change), 1, 'first' );
if isempty(cI)
continue;
end
if cI == nCOLS % no more elements to find min and max from
result(row, 1) = x(cI);
continue;
end
[minV, minI] = min(x( (cI+1):end ));
if (cI + minI) == nCOLS % no more elements to find max from
result(row, 1:3) = [x(cI), minV, minI];
end
[maxV, maxI] = max(x( (cI+minI+1):end ));
result(row, :) = [x(cI), minV, minI, maxV, maxI, (minI + maxI)];
end