2015-12-02 93 views
-2

我有一個矩陣,它有固定的118行和多於40000個樣本的列,但總是具有相同的長度。如何在某些行中插入零並從零行計算

我需要消除某些行並在其中插入零。 最好是能有像

Badchannels變量=

[行數與零更改] ... ...之後,

我必須做出計算與函數,我已經從第1行到零之前的信號。之後,週期應該跳過零,並計算行後零直到下一行零...... ......等等...任何幫助將不勝感激

回答

0

不清楚什麼你的意思,但如果你有一個矩陣:

A = rand(118, 40000); 

而且你想用零來替換以下行索引:

Badchannels = [2 7 18 22]; 

你只要寫:

A(Badchannels, :) = 0; 

這將置零中的所有列在由Badchannels指數

表示排

編輯(塊處理)

對於處理模塊這是不好的通道之間,你可以這樣來做:

function [] = foo() 
%[ 
    A = rand(118, 40000); 
    Badchannels = [2 7 21 22 23 40 45]; 

    rstart = 1; % Init start row 
    Badchannels = unique(Badchannels); % Sort bad channels and make them unique (just in case they wouldn't be) 
    Badchannels(end+1) = size(A, 1)+1; % Add (rcount+1) for end condition in below loop 

    % Block processing 
    for ri = 1:length(Badchannels), 

     % Define stop row 
     rstop = Badchannels(ri) - 1; 

     % Select the processing block 
     block = A(rstart:rstop, :);     

     % Careful for empty selections (contiguous bad channels) 
     if (~isempty(block)),    
      fprintf('Processing block from row=%i to row=%i\n', rstart, rstop); % Do your processing here ... 
     end 

     % Update start row for next block 
     rstart = Badchannels(ri) + 1; 

    end 
%] 
end 

隨着上述[2 7 21 22 23 40 45]壞信道這給:

Processing block from row=1 to row=1 
Processing block from row=3 to row=6 
Processing block from row=8 to row=20 
Processing block from row=24 to row=39 
Processing block from row=41 to row=44 
Processing block from row=46 to row=118 
+0

非常感謝,這是完美的。然而,現在我必須寫一個for循環,我必須做一個計算從行X到通道之前的行充滿零..你如何建議繼續? – Ace

+0

@AlessandroDelVecchio,請參閱我的答案中的編輯(希望這是你的意思)。 – CitizenInsane

+0

非常感謝,這是完美的,但我不知道如何使它工作。我只會告訴你我的代碼,所以也許你可以如此善意地幫助實現這個功能。 – Ace