在Matlab中使用IF循环和单调数据

时间:2016-04-14 13:50:04

标签: matlab

我正在尝试在时间向量中选择特定数据来指定特定的起点。

Vit_lim = 5*(max(dcursor))/100
A = find(dcursor > Vit_lim)

A = [1 2 3 4 5 6 7 8 158 159 160.........318]

起点被视为第一个值。

最初的8个值是误报(并不代表实际起点(158)。

如果第一个值单调增加20个连续值,我需要添加一个找到起始点的条件。

这是一个更大的循环。

2 个答案:

答案 0 :(得分:0)

所以,

A = [1 2 3 4 5 6 7 8 158 159 160.........318]

found=0;
idx=1;
monoticSum=0;
tempValue=A(1);
idx=2;

While found == 0
temp=A(idx);
if ((tempValue+1) == temp)
  monoticSum = monoticSum+1;
  tempValue = temp;
else
  monoticSum = 0
end
if (monoticSum == 20)
  found=1;
  break
end
idx=idx+1
end

这应该有效。 实际上,这是一个很好的起点。但如果发现任何小于20的转换,则需要重新启动变量monoticSum。我已更新。

答案 1 :(得分:0)

鉴于您的样本数据有8个错误启动值,我不确定20个连续值的含义。但是这里的想法是找到一个距离前一个

至少20的样本
b=find(diff(A)>20);
start_idx = A(b+1);