How can I remove NaN values from a 7862x6 cell?
이전 댓글 표시
Hello, Matlab community:
I have a 7862x6 cell (variable name = A) that has NaN values at the end of some of the columns of data (hundreds of consecutive data points). How can I remove the NaNs so that I can find the true length of each column? I have looked through many current threads, but those solutions have not worked for my purpose. I think the problem is that I need a loop to work through the columns and rows, though I am not sure how to approach it. Any suggestions are appreciated!
- John
댓글 수: 1
Vrajeshri Patel
2016년 9월 7일
You can't remove them because it would change the size of the matrix.If you just want to find the length of the column (not including nan entries), here's an example:
k=[5 6 nan; 1 nan 3; 1 2 2];%example matrix
k(find(~isnan(k)))=1;%replace all non-nan numbers with 1s
s=nansum(k,1);%sum the values
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!