Removing NaN from matrix with strings and numbers

9 visualizaciones (últimos 30 días)
Diogo Queirós
Diogo Queirós el 29 de En. de 2015
Comentada: Jan el 28 de Jun. de 2018
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 comentarios
Diogo Queirós
Diogo Queirós el 29 de En. de 2015
it's a really big project i'm working on and it's all in portuguese soi'm going to try to explain myself better. i'm extracting from an excel file a table, call it A.
A=
[1x26 char] 'Início' 'Fim' [1x20 char] [ NaN]
[2.0088e+03] 'SE S M Portuzelo' 'PTD 0526' [ 18.6057] [ NaN]
[ 169.0442] 'PTC 5452' 'PTD 0450' [ 18.6057] [ NaN]
[ 446.3509] 'PTD 0039' 'PTC 2850' [ 18.6057] [ NaN]
[ 635.2552] 'PTD 0450' 'PTD 0039' [ 18.6057] [ NaN]
[ 255.5464] 'PTD 0450' 'PTD 0090' [ 18.6057] [ NaN]
[4.2281e+03] 'PTD 0526' 'PTC 5452' [ 18.6057] [ NaN]
[ NaN] [ NaN] [ NaN] [ NaN] [ NaN]
[ NaN] [ NaN] [ NaN] [ NaN] [ NaN]
note that the table is much larger, i just took a sample.
all my attempts got me that same error
Undefined function 'isnan' for input arguments of type 'cell'
unless this one that removed all of the NaN but completely disformed my matrix
cabos(cellfun(@(cabos) any(isnan(cabos)),cabos)) = []
Guillaume
Guillaume el 29 de En. de 2015
Editada: Guillaume el 29 de En. de 2015
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};

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 29 de En. de 2015
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 comentarios
VBBV
VBBV el 28 de Jun. de 2018
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
Jan el 28 de Jun. de 2018
@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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by