Removing invalid results knowing the trend

조회 수: 2 (최근 30일)
marco esteves
marco esteves 2019년 8월 22일
댓글: Adam Danz 2019년 8월 23일
Hello,
I have a matrix, which is an output from angle measurement from a motor. So, over time the angle increases over time until it reaches a maximum (360 i.e) and then stops or descreases.
. For instance:
[0 10 -1 40 50 0 60 10 90 0 ]
How can I remove the invalid values, that in that example are the -1 , second and third '0's and the second 10 ?
Thank you
  댓글 수: 2
the cyclist
the cyclist 2019년 8월 22일
What is the general rule for "invalid"?
Adam Danz
Adam Danz 2019년 8월 22일
편집: Adam Danz 2019년 8월 22일
Your rule should produce a logical vector where True indicates data that should be removed and False indicates data that should be retained. Then you have 2 options.
data(idx) = NaN; % replace the unwanted values with NaN
% or
data(idx) = []; %remove the unwanted values.
The benefit of the first method is that the index of each data point within the vector is retained. So data(4) will always be 40 before and after you replace the unwanted data.

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

채택된 답변

Ted Shultz
Ted Shultz 2019년 8월 22일
편집: Ted Shultz 2019년 8월 22일
From what you say, it sounds like your valid rule is that if the reported angle is invalid if it is less than the previous value.
A simple slow way to test for this is:
ang = [0 10 -1 40 50 0 60 10 90 0 ];
% find ang(n) < ang(n-1) and remove
for ii = numel(ang):-1:2
if ang(ii) < ang(ii-1)
ang(ii) = [];
end
end
disp(ang)
output: 0 10 40 50 60 90
  댓글 수: 3
marco esteves
marco esteves 2019년 8월 23일
편집: marco esteves 2019년 8월 23일
I think this the most elegant choice. thank you!
@adam is it possible to save the indexes of the nonvalid values ?
Adam Danz
Adam Danz 2019년 8월 23일
Sure. The indices are computed with in the square brackets above. It assumes the first value is never a nonvalid value. Any following value is nonvalid if it's less than the previous value as Ted explained.
[false,diff(ang)<=0]

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by