how to convert num to string ?

I have data in one column as follows
x =
[22]
'22 .8 '
[30]
'39 .6 '
[44]
[48]
'49 .6 '
'50 .8 '...
how do I convert to a string?
I have tried using str2double (x) but it displays the results
Nan
22.8000
Nan
39.6000
Nan
Nan
49.6000
50.8000
I am confused when in one data there are 2 different data, namely ('x' and [x])..
I am very grateful to those who have been kind enough to help me
Regards
Jan

 Respuesta aceptada

KSSV
KSSV el 30 de Abr. de 2019

0 votos

x = { [22]
'22 .8 '
[30]
'39 .6 '
[44]
[48]
'49 .6 '
'50 .8 '} ;
idx = cellfun(@ischar,x) ;
y = cellfun(@num2str,x(~idx),'un',0)
x(~idx) = y ;
x

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 30 de Abr. de 2019

0 votos

x ={...
[22]
'22 .8 '
[30]
'39 .6 '
[44]
[48]
'49 .6 '
'50 .8 '};
lo = cellfun(@ischar,x);
out = zeros(size(x));
out(~lo) = cell2mat(x(~lo));
out(lo) = str2double(regexprep(x(lo),'\s',''));

1 comentario

Jan Risn
Jan Risn el 30 de Abr. de 2019
thank you for your help, this really helped me

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Preguntada:

el 30 de Abr. de 2019

Comentada:

el 30 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by