如何在数据列中找到最大变化点并用条件语句编写
How do I find maximum change point in data columns and write this with a conditional statement
MATLAB.
我有一个名为 ydisplacements 的 (2559 x 16 x 3) 数组。我使用具有指定阈值的 'ischange' 命令,在一个循环中为所有三个平面查找每列数据中快速变化的点。我将其记录在一个逻辑数组 TF(2559 x 16 x 3) 中,其中“1”表示急剧变化的点。
我想让 TF 在它的每一列中只有 'ydisplacements' 的最极端变化被记录为逻辑 1。换句话说,其他一切都是逻辑 0,我只想要一个逻辑 1 TF 的列。我可以通过增加阈值直到我想要的结果来轻松地做到这一点。但我的问题是如何实现自动化,以便对于 ydisplacements(:,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
、returns FALSE
并继续嵌套 2-for 循环的下一次迭代。
但是,正如我所说,这是我的想法,如果没有您的矩阵示例,我无法确定。顺便说一句,可能有更好的方法来获得最极端的变化,而不是使用嵌套的 for 循环。
MATLAB. 我有一个名为 ydisplacements 的 (2559 x 16 x 3) 数组。我使用具有指定阈值的 'ischange' 命令,在一个循环中为所有三个平面查找每列数据中快速变化的点。我将其记录在一个逻辑数组 TF(2559 x 16 x 3) 中,其中“1”表示急剧变化的点。 我想让 TF 在它的每一列中只有 'ydisplacements' 的最极端变化被记录为逻辑 1。换句话说,其他一切都是逻辑 0,我只想要一个逻辑 1 TF 的列。我可以通过增加阈值直到我想要的结果来轻松地做到这一点。但我的问题是如何实现自动化,以便对于 ydisplacements(:,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
、returns FALSE
并继续嵌套 2-for 循环的下一次迭代。
但是,正如我所说,这是我的想法,如果没有您的矩阵示例,我无法确定。顺便说一句,可能有更好的方法来获得最极端的变化,而不是使用嵌套的 for 循环。