[英]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 的每一列特遣部隊。 我可以通過增加閾值來輕松做到這一點,直到我想要的結果。 但我的問題是如何實現自動化,以便對於 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
,返回FALSE
並繼續嵌套 2-for-loop 的下一次迭代。
但是,正如我所說,這是我的想法,如果沒有您的矩陣示例,我無法確定。 順便說一句,可能有更好的方法來獲得最極端的變化,而不是使用嵌套的 for 循環。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.