简体   繁体   English

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

[英]How do I find maximum change point in data columns and write this with a conditional statement

MATLAB. MATLAB。 I have a (2559 x 16 x 3) array named ydisplacements.我有一个名为 ydisplacements 的 (2559 x 16 x 3) 数组。 I use the 'ischange' command with a specified threshold, in a loop to find points of rapid change in the data in each column, for all three planes.我使用具有指定阈值的“ischange”命令,在循环中为所有三个平面查找每列数据中快速变化的点。 This I record in a logical array TF(2559 x 16 x 3) in which '1' denotes points of sharp change.我将此记录在一个逻辑数组 TF(2559 x 16 x 3) 中,其中“1”表示急剧变化的点。 I want to have TF such that in each of its columns only the most extreme change from 'ydisplacements' is recorded in it as logical 1. In other words, everything else is a logical 0, I want only one logical 1 for each column of TF.我希望 TF 使得在它的每一列中,只有从 'ydisplacements' 最极端的变化被记录为逻辑 1。换句话说,其他一切都是逻辑 0,我只想要一个逻辑 1 的每一列特遣部队。 This I can do easily by increasing the threshold till my desired outcome.我可以通过增加阈值来轻松做到这一点,直到我想要的结果。 But my question is how I can automate this so that for each column of ydisplacements(:,i,j), the threshold keeps increasing by a predetermined value until the desired outcome of only one logical 1 is achieved in TF, before moving to the next index.但我的问题是如何实现自动化,以便对于 ydisplacements(:,i,j) 的每一列,阈值不断增加一个预定值,直到在 TF 中仅实现一个逻辑 1 的期望结果,然后再移动到下一个索引。 I have tried this code below.我在下面尝试了这段代码。 Any help is appreciated.任何帮助表示赞赏。 Thank you..谢谢..

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

Not 100% sure without an example data.如果没有示例数据,则不能 100% 确定。 But it is very likely using if-else statment will only increment the threshold once.但是很可能使用 if-else 语句只会增加一次阈值。 What I would do is using a while-loop as a unlimited iterative if statement.我要做的是使用 while 循环作为无限迭代 if 语句。 Something like:就像是:

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

The while-loop should iterate until there's only 1 TRUE value in TF(:,i,j), so then it check again sum(TF(:,i,j) == 1)>1 , returns FALSE and continue to the next iteration of the nested 2-for-loops. while 循环应该迭代直到 TF(:,i,j) 中只有 1 个TRUE值,然后它再次检查sum(TF(:,i,j) == 1)>1 ,返回FALSE并继续嵌套 2-for-loop 的下一次迭代。

But, as I said, this is my idea and I can't be sure without an example of your matrix.但是,正如我所说,这是我的想法,如果没有您的矩阵示例,我无法确定。 By the way, probably there are better ways to get the most extreme change rather than using nested for-loops.顺便说一句,可能有更好的方法来获得最极端的变化,而不是使用嵌套的 for 循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM