A simple allocation of array places to zero does not work in MATLAB R2020B

4 次查看(过去 30 天)
I have a numeric array KSE
I have identified a number of locations where there are peaks,
locations =
Columns 1 through 10
147 827 3772 4762 5192 5618 6048 6481 6915 7350
Columns 11 through 20
7781 8206 8637 9070 9502 9938 10367 10793 11225 11657
Columns 21 through 26
12922 13876 20315 23377 24431 25492
I have identified in that array a number of locations where there are short lived transients, a number of which I wish to remove.
Those unwanted transients are identified by
ii =
1 2 3 21 22 23 24 25 26
The command
KSE(locations(ii)-50:locations(ii)+50)=0
is meant to replace 50 array elements on either side of the transient location with a zero.
It works well at the first location but not in the remaining 8 locations!
Is this a bug or am I doing some sort of stupid coding mistake?
Any soultions would be appreciated!
  3 个评论
Branko Celler
Branko Celler 2024-8-1
I am not sure that I can be more explicit!
KSE is an an array of numbers. In that array are a number of transients I wish to remove.
I know the location of the transients (locations)
I know the subset of the locations of the transients I wish to remove (array ii)
I want to replace each unwanted transient with 50 samples on either side of the location set to zero using the command
KSE(locations(ii)-50:locations(ii)+50)=0;
only the first location in ii is processed!
Branko Celler
Branko Celler 2024-8-1
I am not sure I can be more explicit. I have a data array KSE.
In that array I have identified a number of peaks located in 'locations'
A number of those peaks are spurious transients I wish to remove the transient locations are identified in array 'ii'
I want to remove those transients by replacing the values of KSE 50 samples on either side of the centre location with zeros, using the command
KSE(locations(ii)-50:locations(ii)+50)=0;
Only the first instance of ii works as expected.

请先登录,再进行评论。

采纳的回答

Voss
Voss 2024-8-1
编辑:Voss 2024-8-1
One solution is to construct a matrix of indices:
KSE(locations(ii)+(-50:50).') = 0;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by