필터 지우기
필터 지우기

How to: Delete nums if before NaN

조회 수: 2 (최근 30일)
Hello kity
Hello kity 2013년 1월 30일
I have the following data (matrix).
I need to delete it if there is only 1 datapoint, 2 or more should stay. so in this example, -12.5 should be deleted.
Matrix=[NaN;NaN;-12.5000000000000;NaN;NaN;-8.90000000000000;-9.20000000000000;NaN;NaN;-9.60000000000000;-9.60000000000000;-9.60000000000000;NaN;]
Condition:
If num - 1 index = NaN and num + 1 = NaN
Delete that row
end
NaN
NaN
-12,5000000000000
NaN
NaN
-8,90000000000000
-9,20000000000000
NaN
NaN
-9,60000000000000
-9,60000000000000
-9,60000000000000
NaN
thank you
  댓글 수: 1
Jan
Jan 2013년 1월 30일
편집: Jan 2013년 1월 30일
Please provide data such that we can use it by copy&paste for Matlab code. This means surrounding brackets, less trailing zeros and decimal points instead of commas. Thanks.

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

채택된 답변

Jan
Jan 2013년 1월 30일
편집: Jan 2013년 1월 30일
value = [NaN, NaN, -12.5, NaN, NaN, -8.9, -9.2, NaN, ...
NaN, -9.6, -9.6, -9.6, NaN];
index = strfind(isnan(value), [true, false, true]);
value(index + 1) = [];
[EDITED] Perhaps you need a transpose(value), because strfind requires a row vector.
  댓글 수: 1
Hello kity
Hello kity 2013년 1월 30일
편집: Hello kity 2013년 1월 30일
thank you
strfind was the function i was looking for :)
really greateful
*edit, it is a column, i look if it is necessary

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by