在Matlab中移动窗口

时间:2014-11-26 17:00:25

标签: matlab window pca

我希望使用Matlab来运行一组数据,5446100 x 6,称为xdata1。
我正在查看它绘制前100个数据点,然后单独运行每个点。
首先,我有:

表示i = 1:100
NOC1 = CPMD_PCA(xdata1(99 + i,:);

除了写出i = 2:101,i = 3:102等之外,我怎样才能继续这样做?

2 个答案:

答案 0 :(得分:0)

我不确定CPMD_PCA正在做什么,所以我将向您展示如何在样本数据集上的简单matlab图上绘制移动窗口。

您必须根据具体应用调整代码。

%% // just to create a sample set
x = ( 0:pi/10:150*pi ).' ; %//'
y = cos(x).*cos(3*x)+cos(x./4) ;
xdata = [y , -y/2] ;

%% // adjust moving window size and compute other useful parameters
window_size = 100 ;                 %// the length (in points) of the moving window
nPts = size(y,1) ;                  %// number of points in a column
n_windows = nPts-window_size ;      %// the total number of windows

%% // Do the initial plot (not moving yet) of the first 100 points
idx = 1:window_size ;
hp = plot( xdata( idx , 1) ) ;

%% // Move the plot by one point at each iteration of the loop
for iwin =1:n_windows
    idx = idx + 1 ;
    set( hp , 'YData' , xdata(idx,1) )
    drawnow                         %// you can comment that line (try with and without)
    pause(0.1)                      %// adjust the timing to your needs
end

答案 1 :(得分:0)

要直接回答您的问题,您可以将当前代码包装在另一个循环中:

for outer_loop_index = 1 : (size(xdata1,1) - 100)
    for inner_loop_index = outer_loop_index : outer_loop_index + 99
        NOC1 = CPMD_PCA(xdata1(inner_loop_index,:); 
    end
end