Cell array / Concatenate non - NaN results
Mostrar comentarios más antiguos
Dear all,
I have a cell array that looks like this :
A = {
[NaN]
[NaN]
'a'
'[b c]'
[NaN]
'b' }
what I would like to obtain is this array without NaNs, and all "non-Nan" values concatenated, i.e.
B = {
'a'
'b'
'c'
'b'}
I would like to avoid doing different "for" loops, I mean doing it in the shortest way possible :)
I'm unsure on how to obtain this..
Thanks in advance !
4 comentarios
Are the non-NaN cells really char vectors or are they actually numeric arrays?
If they really are char vectors, then a) why have you got numeric values (NaNs) mixed with text? and b) we need more details of what should happen to text with multiple characters in a cell.From your example it would appear that spaces and brackets need to be removed, what other characters? and that the remaining characters need to be split into individual cells. An odd thing to want.
If the cells are actually numeric arrays. What is their shape? Are they row vectors or scalar as your example would imply or can they be matrices, column vectors, or any shape really?
Eara Eara
el 10 de Abr. de 2019
Alex Mcaulley
el 10 de Abr. de 2019
is that an exeption? Are there more different cells? I mean, for example:
'[a;b]'
'[a,b;c,d]'
Eara Eara
el 10 de Abr. de 2019
Respuesta aceptada
Más respuestas (1)
Alex Mcaulley
el 10 de Abr. de 2019
A(cellfun(@isnan,A)) = [];
2 comentarios
Eara Eara
el 10 de Abr. de 2019
Alex Mcaulley
el 10 de Abr. de 2019
Editada: Alex Mcaulley
el 10 de Abr. de 2019
Try this instead: (this code is to remove the nan values, for non nan values we need more information as Guillaume said)
A(logical(cellfun(@sum,cellfun(@isnan,A,'UniformOutput',false))))=[];
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!