필터 지우기
필터 지우기

How does tilde remove NaN's from dataset?

조회 수: 2 (최근 30일)
Ralph
Ralph 2014년 3월 3일
댓글: Ralph 2014년 3월 3일
Given a C = m x n matrix of 1's and 0's, and a data set B = r x s with NaN's mixed in with numeric data, how do I use the tilde to remove the NaN's? I have seen this in an example:
A=B(~C,:); and it worked in the example.
I cannot recreate it in a different problem. I also cannot find any explanation in any Mathworks information that explains it.

채택된 답변

Walter Roberson
Walter Roberson 2014년 3월 3일
You are not applying ~ to the NaNs, you are applying ~ to the matrix of 0 and 1. ~ is logical negation, so all the places in C that were 0 become "true" (1) and all the places in C that were anything else become "false" (0). That matrix of true and false is then used "logical indexing". You can read about that Steve's Blog
  댓글 수: 1
Ralph
Ralph 2014년 3월 3일
Thank you for responding, Walter. I think that may clear up my confusion.

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

추가 답변 (1개)

Rick Rosson
Rick Rosson 2014년 3월 3일
Is this what you are trying to do?
C = isnan(B);
A = B(~C);
  댓글 수: 1
Ralph
Ralph 2014년 3월 3일
Hi, Rick. I think the other response I received may explain my confusion on using tilde. Thank you for responding.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by