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
uj5u.com熱心網友回復:
如果沒有示例資料,就不能 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 回圈應該迭代直到TRUETF(:,i,j) 中只有 1 個值,然后它再次檢查sum(TF(:,i,j) == 1)>1,回傳FALSE并繼續嵌套 2-for 回圈的下一次迭代。
但是,正如我所說,這是我的想法,如果沒有您的矩陣示例,我無法確定。順便說一句,可能有更好的方法來獲得最極端的變化,而不是使用嵌套的 for 回圈。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/374249.html
下一篇:通過鍵串列離開物件。純JS
