如何在数据列中找到最大变化点,并用条件语句编写



MATLAB我有一个(2559 x 16 x 3(数组,名为ydisplacements。我使用具有指定阈值的"ischange"命令,在循环中查找所有三个平面的每列数据中的快速变化点。这个I记录在逻辑数组TF(2559 x 16 x 3(中,其中"1"表示急剧变化的点。我想让TF在它的每一列中,只有来自"ydisplacements"的最极端的变化被记录为逻辑1。换句话说,其他所有东西都是逻辑0,我只希望TF的每列有一个逻辑1。我可以通过增加阈值来轻松做到这一点,直到我想要的结果。但我的问题是,我如何将其自动化,以便对于每一列的yddisplacements(:,I,j(,阈值保持增加预定值,直到在TF中仅获得一个逻辑1的期望结果,然后再转到下一个索引。我已经尝试过下面的代码。感谢您的帮助。非常感谢。

increment = 100;
for i = 1:size(ydisplacements,2);
for j = 1:size(ydisplacements,3);
threshold = 100;
TF(:,i,j) = ischange(ydisplacements(:,i,j),'Linear','Threshold',threshold);
if sum(TF(:,i,j) == 1)>1; 
threshold = threshold + increment;
TF(:,i,j) = ischange(ydisplacements(:,i,j),'Linear','Threshold',threshold);
else
threshold = threshold;
TF(:,i,j) = ischange(ydisplacements(:,i,j),'Linear','Threshold',threshold);
end
end
end

如果没有示例数据,就不能100%确定。但使用if-else语句很可能只会增加阈值一次。我要做的是使用while循环作为一个无限制的迭代if语句。类似于:

increment = 100;
for i = 1:size(ydisplacements,2);
for j = 1:size(ydisplacements,3);
threshold = 100;
TF(:,i,j) = ischange(ydisplacements(:,i,j),'Linear','Threshold',threshold);
while sum(TF(:,i,j) == 1)>1  % Iterate always sum(TRUEs) > 1
threshold = threshold + increment;
TF(:,i,j) = ischange(ydisplacements(:,i,j),'Linear','Threshold',threshold);
end
end
end

while循环应该迭代,直到TF(:,i,j(中只有1个TRUE值,然后再次检查sum(TF(:,i,j) == 1)>1,返回FALSE,并继续进行嵌套的2-for-roops的下一次迭代。

但是,正如我所说,这是我的想法,如果没有你矩阵的例子,我无法确定。顺便说一句,可能有更好的方法来获得最极端的更改,而不是使用嵌套的for循环。

最新更新