嗨我有一列值的Matlab(PDS(:,39))。此列針對各種情況進行了過濾,並且有兩個分隔標記列(PDS(:,[41 81])),它們對於有效行是0或對於無效行是-1。我正在考慮有效數據的均值,如果均值大於0,我想使這個值無效,並再次採用均值,直到均值低於某個值(在本例中爲0.2)。這裏是我的代碼:迭代地取平均值在Matlab列
% identify the VALID values
U1 = (PDS(:,81)==0);
F1 = (PDS(:,41)==0);
% only calculate using the valid elements
shearave = mean(PDS(U1&F1,39));
while shearave > 0.2
clear im
% determine the largest shear value overall for filtered and
% non-flagged
[c im] = max(PDS(U1&F1,39));
% make this value a NaN
PDS(im,39)=NaN;
% filter using a specific column and the overall column
PDS(im,41)=-1;
F1 = (PDS(:,41)==0);
% calculate shear ave again using new flagging column - remove the ";" so I can see the average change
shearave = mean(PDS(U1&F1,39))
end
是Matlab的給我的輸出是:
shearave =
0.3032
shearave =
0.3032
shearave =
0.3032
等
迴路不與新的有效數據重新evalulating。我該如何解決這個問題?我必須使用休息還是繼續?或者也許是一種不同類型的循環?謝謝你的幫助。
+1,非常聰明! –
是的,我剛剛得出同樣的結論!對它進行降序排序並刪除值,直到平均值低於0.2,根據時間戳識別我必須刪除的值。我雖然有一個循環 - 這會有所幫助。謝謝! – user1854628