Removing NaN from matrix with strings and numbers
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm having trouble removing NaN from this matrix
cabos=
[1x26 char] 'Início' 'Fim' [1x20 char] 'N. volt. level [KV]'
[2.0088e+03] 'SE S M Portuzelo' 'PTD 0526' [ 18.6057] [ 15]
[ 169.0442] 'PTC 5452' 'PTD 0450' [ 18.6057] [ 15]
[ 446.3509] 'PTD 0039' 'PTC 2850' [ 18.6057] [ 15]
[ 635.2552] 'PTD 0450' 'PTD 0039' [ 18.6057] [ 15]
[ 255.5464] 'PTD 0450' 'PTD 0090' [ 18.6057] [ 15]
[4.2281e+03] 'PTD 0526' 'PTC 5452' [ 18.6057] [ 15]
[ NaN] [ NaN] [ NaN] [ NaN] [ NaN]
[ NaN] [ NaN] [ NaN] [ NaN] [ NaN]
[ NaN] [ NaN] [ NaN] [ NaN] [ NaN]
I tried this code and it removes de NaN values, but it completely rearanges the matrix and i can't solve this
cabos(cellfun(@(cabos) any(isnan(cabos)),cabos)) = []
댓글 수: 5
Guillaume
2015년 1월 29일
편집: Guillaume
2015년 1월 29일
If your code
cabos(cellfun(@(cabos) any(isnan(cabos)),cabos)) = []
does not give you the error Undefined function 'isnan' for input arguments of type 'cell', then neither would mine.
I suspect you've tried Stalin's code, whose first line modified your cabos cell array. And yes, after that, on that my code (but yours as well) you would get the error.
Reload your cabos from file or do:
cabos = cabos{1};
채택된 답변
Guillaume
2015년 1월 29일
Possibly, this is what you want. But see comments to your question.
cabos(cellfun(@(c) isscalar(c) && isnan(c), cabos)) = {[]}
This will replace NaNs with empty matrices. The benefit of which is not obvious to me.
댓글 수: 9
VBBV
2018년 6월 28일
Hi ... I am currently working on similar problem, however, I want to replace NaN in double/logical array with character 'A' to appear ... how can I do it ... Many thanks for any help
Jan
2018년 6월 28일
@Vasishta Bhargava: Please do not hijack a thread by appending a new question as comment to an answer. Open a new thread instead.
Then ths answer will be: This cannot work. You cannot insert characters in a numerical or logical array. All arrays, except for cell arrays, must have the same data type for all elements.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!