2017-05-23 32 views
1

我是noob,我發現碎片窗口上的堆棧信息非常分散。麻煩理解滑動窗口爲矩陣的一列,在Matlab中的一般和特定情況

我有一個mXn矩陣,其中m是固定的(緯度,經度,ax,ay,az),n可以從不同的日誌中改變。

1)我怎樣才能創建一個滑動窗口只爲az而不提取矢量然後分析它?

2)如果我想保存az標準偏差超過定義的閾值的所有行,我該怎麼做?

3)如果日誌長度不是固定的,我該如何處理? (例如:一個文件包含932行,而另一953)

4)我讀了很多的問題,我學習bsxfun如何在這種情況下,但很不清楚,我(in this examples我只undestood是 一個新的矩陣創建的基礎上,窗口大小,然後將新的矩陣分析)(這最後一個問題是密切相關的我的土建工程師背景)


這裏我學到的東西,並試圖聚集。

滑動窗口是一個功能強大的工具,可以分析信號或圖像。 當我試圖來形容我的女朋友我在做什麼,我解釋 「就像讀一本書用放大鏡, 放大鏡有一個定義的尺寸和你分析文本」

Sliding Window

基本Matlab的方式,而不是最有效的,這樣做是

1.定義向量維

2.定義你的Wi ndow尺寸

3.定義的步驟

數這裏,我寫

a= randi(100,[1,50]);  %Generic Vector 
win_dim=3;     %Generic window size 

num_stps=(length(a)-win_dim) %number of "slides", we need to subtract win_dim to avoid that the window will go over the signal 
threshold= 15 %Generic number only for the example 
for i= 1:num_stps 
    mean_win(i)=mean(a(i:i+win_dim -1); %we subtract 1 or we make an error, and the code analyzes a segment bigger than one unit 
    std_win(i)=std(a(i:i+win_dim -1); %example for i=2 if we don't subtract 1 our segment starts from 2 until 5, so we analyze 
             % 2 3 4 5, but we defined a window dimension of 3 
    If std_win(i)> threshold 
    std_anomalies=std_win(i)    %here i think there is an error         
end  

這樣,代碼滑過整個信號的基本示例,但窗口將重疊

如何確定「重疊比率」(或幻燈片增量)?

我們可以將其定義爲「兩個相鄰窗口共享多少信息?「 Half Segment Overlap 以下實施例I所做的是完全錯誤的,但我想詢問在這裏,我們的目標本來希望成爲半段的或沒有重疊

%Half segment overlap 

a= randi(100,[1,20]); %Generic Vector 
win_dim=4; %generic window size  
%v is the increment vector in our case we desire to have 50% of overlap 
l= win_dim 
if l%2==0 
    v=l/2 
else 
    v=(l+1)/2 
end  

for i= 1:num_stps 
    if (i==1) 
    mean_win(i)=mean(a(1:1+win_dim -1); 
    else 
    mean(i)= mean(a (i+v:i+win_dim+v-1); 
end 

回答

2

我的重疊之前代碼的東西喜歡創作手法的問題!:)這是你在找什麼?

a = rand(100, 5); % the data 

window_size = 5; % size of the window 
overlap = 2; % desired overlap 
step = window_size - overlap; % compute the step 

threshold = 0.3; % large std threshold 

std_vals = NaN(size(a, 1), 1); 
for i=1:step:(size(a, 1) - window_size) 
    std_vals(i) = std(a(i:(i+window_size-1),5)); % calculate std of 5th col 
end 

% finding the rows with standard deviation larger than threshold 
large_indexes = find(std_vals>threshold); 

large_indexes會給你有個標準差大於閾值窗口的起始行。std_vals將存儲所有的標準偏差,以備日後需要時使用。

如果您想您的滿意門檻窗口中的所有行的索引,你可以在年底

large_windows = zeros(numel(large_indexes), window_size); 
for i=1:window_size 
    large_windows(:,i) = large_indexes + i - 1; 
end 

其中large_windows各行給出了窗口行的索引添加此。

+0

我需要一些澄清。 你選擇'Nan'來初始化std_vector?爲什麼? 是我第一次看到雙':'它是如何工作的?我總是看到只有一個 如何保存窗口中具有滿足不等式關係的(i,5)元素的所有行,而不僅僅是單個元素? Tnx爲您的時間,併爲我的啞巴問題抱歉<3:D –

+0

對於給定的行沒有可用的值,所以NaN對我來說是最合理的選擇。它使得測試閾值更容易。有關冒號,請參閱https://uk.mathworks.com/help/matlab/ref/colon.html。我編輯了答案,以獲得組中的所有行號。我會建議閱讀文檔並自己嘗試一下,這是正確學習的唯一方法。 –

+0

如何在我的情況下使用'bsxfun(@ plus'爲滑動窗口,就像本例中的[鏈接](https://stackoverflow.com/questions/7099590/how-do-i-select-n-elements m-matlab的窗口中的序列)? –