我有一个矩阵,它固定了118行和超过40000个样本的列,但始终具有相同的长度。
我需要消除某些行并在其中插入零。 最好的是有一个像
这样的变量Badchannels = [用零更改的行数]
...
之后,我必须使用我已经从第1行到零之前的信号的函数进行计算。在那之后,循环应该跳过零,并在下一个零之前将零直接计算到下一行......等等......任何帮助都将受到高度赞赏
答案 0 :(得分: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