필터 지우기
필터 지우기

how to remove unwanted data from an arry

조회 수: 26 (최근 30일)
zach johnson
zach johnson 2017년 6월 22일
편집: Andrew Shum 2017년 6월 26일
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
Andrew Shum
Andrew Shum 2017년 6월 22일
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 2017년 6월 22일
편집: Zachariah Johnson 2017년 6월 22일
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

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2017년 6월 22일
편집: Star Strider 2017년 6월 23일
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
Zachariah Johnson
Zachariah Johnson 2017년 6월 23일
ok I see, Thanks again for your help this worked great.
Star Strider
Star Strider 2017년 6월 23일
My pleasure.
If my Answer helped you solve your problem, please Accept it!

댓글을 달려면 로그인하십시오.


Andrew Shum
Andrew Shum 2017년 6월 22일
편집: Andrew Shum 2017년 6월 26일
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
Zachariah Johnson
Zachariah Johnson 2017년 6월 23일
편집: Zachariah Johnson 2017년 6월 23일
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 2017년 6월 26일
My bad. If you still need a solution for future use, try the modified version I am about to add.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by