how to remove unwanted data from an arry

35 views (last 30 days)
zach johnson
zach johnson on 22 Jun 2017
Edited: Andrew Shum on 26 Jun 2017
I have measured data that has some information outside the zone of interest.
the "wings" at either end of the plot attached are the unwanted data.
I am trying to write a script to analyze many data sets with similar issues is there a way to remove that from all data sets. I need to remove the same points from both the x and y sets of data.
  2 Comments
Andrew Shum
Andrew Shum on 22 Jun 2017
Do you need to remove it from the arrays or just not plot them? Also, what type of criteria are you using to determine the values. Is it a continuous index range or specific, potentially isolated indices?
Zachariah Johnson
Zachariah Johnson on 22 Jun 2017
Edited: Zachariah Johnson on 22 Jun 2017
I would like to remove it from the array because I will later be processing the data from these arrays.
The values that I do not need are outside the maxima, <-125 and <125, but these maxima may move depending on how the data was collected.
sorry, this is from a different account I realized I was logged in on my old work account and would receive notifications

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 22 Jun 2017
Edited: Star Strider on 23 Jun 2017
If you have the Signal Processing Toolbox, use the findpeaks function to identify the indices of the peaks. Then delete the data less than the first index and greater than the second index.
EDIT In the absence of findpeaks, try this:
x = linspace(-140, 140); % Simulate Data
y = x.^2/1500; % Simulate Data
y(1:9) = y(10)-y(1:9); % Simulate Data
y(end-10:end) = y(end)-y(end-10:end); % Simulate Data
L2 = fix(length(x)/2); % Split Data In Half
ixrng1 = 1:L2; % First Index Range
ixrng2 = L2:length(x); % Second Index Range
[~,ix1] = max(y(ixrng1)); % First Maximum
[~,ix2] = max(y(ixrng2)); % Second Maximum
ix2 = ix2+L2-1; % Correct ‘ix2’ For Offset
ClipWings = ix1:ix2; % Data Index Range With ‘Wings’ Deleted
figure(1)
plot(x, y)
hold on
plot(x(ix1), y(ix1), 'pg')
plot(x(ix2), y(ix2), 'pg')
figure(2)
plot(x(ClipWings), y(ClipWings))
Substitute your independent and dependent variables for my ‘x’ and ‘y’ respectively. The rest of my code should work without modification.
  4 Comments
Zachariah Johnson
Zachariah Johnson on 23 Jun 2017
ok I see, Thanks again for your help this worked great.
Star Strider
Star Strider on 23 Jun 2017
My pleasure.
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.


Andrew Shum
Andrew Shum on 22 Jun 2017
Edited: Andrew Shum on 26 Jun 2017
If you don't have the toolbox, you could try this.
idx1=find(xdata(1:round(numel(xdata)/2))<-125);
idx2=find(xdata(round(numel(xdata)/2):end)>125);
xdata=xdata((idx1(end)+1):(idx2(1)-1));
ydata=ydata((idx1(end)+1):(idx2(1)-1));
Edit 1:
Since it isn't at fixed values of x. It will have to be done slightly differently. The following should include the two maxima. If you don't want to include them, change the indices by 1.
idx1=find(ydata(1:round(numel(ydata)/2))==max(ydata(1:round(numel(xdata)/2))));
idx2=find(ydata(round(numel(ydata)/2):end)==max(ydata(round(numel(ydata)/2):end)));
xdata=xdata(idx1(end):idx2(1));
ydata=ydata(idx1(end):idx2(1));
Edit 2:
As you pointed out in the comments, the above solutions accidentally split the data in two.
splitidx=round(numel(ydata)/2);
idx1=find(ydata(1:splitidx)==max(ydata(1:splitidx)));
idx2=find(ydata(splitidx:end)==max(ydata(splitidx:end)));
idx2=idx2-1+splitidx;
xdata=xdata(idx1(end):idx2(1));
ydata=ydata(idx1(end):idx2(1));
  7 Comments
Zachariah Johnson
Zachariah Johnson on 23 Jun 2017
Edited: Zachariah Johnson on 23 Jun 2017
Andrew, correction from my last post, it has cut my data set in half but other than that it worked. to remove the wings
Andrew Shum
Andrew Shum on 26 Jun 2017
My bad. If you still need a solution for future use, try the modified version I am about to add.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!