find indices in a large array and replace them with zeros

3 ビュー (過去 30 日間)
Konstantinos
Konstantinos 2016 年 8 月 17 日
コメント済み: Konstantinos 2016 年 8 月 17 日
I have an index with 10 rows and 301 columns each. I also have a digital signal with 1 X 250,000 elements. The values of the initial index are isolated from the digital signal because they all have a specific characteristic and I used the following code for this:
index1 = zeros(10,151);
index2 = zeros(10,150);
for i = 1:10
index1(i,:) = signal(peak(i):(peak(i)+150));
index2(i,:) = signal((peak(i)-150):(peak(i)-1));
end
index = [index2,index1];
Up to this point everything is fine. However, I want to delete that characteristic by replacing all the index values with zeros back at the digital signal. My problem is that the element arrays in the "index", corresponding to the 10 rows, aren't neighbouring. How can I do this? Would it be easier if I make the replacement within the for loop? Thanks in advance.

採用された回答

Thorsten
Thorsten 2016 年 8 月 17 日
for i = 1:10
index1(i,:) = signal(peak(i):(peak(i)+150));
index2(i,:) = signal((peak(i)-150):(peak(i)-1));
end
Setting the signal to zero at the peak indices:
for i = 1:10
signal((peak(i)-150):(peak(i)+150)) = 0;
end
Note that you cannot do the replacement in the same for loop, since the peak(i)-150):(peak(i)+150) may overlap, an then you pick up zeros instead of the real signal values.
  1 件のコメント
Konstantinos
Konstantinos 2016 年 8 月 17 日
Thanks a lot! It worked! It was finally so simple :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by