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

4 views (last 30 days)
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 Comments
Branko Celler
Branko Celler on 1 Aug 2024
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 on 1 Aug 2024
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.

Sign in to comment.

Accepted Answer

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

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!