how to use cell function to convert string to number

1 visualización (últimos 30 días)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan el 11 de Jun. de 2015
Comentada: madhan ravi el 20 de Dic. de 2018
I have a cell array a = { 'a' '0' ; 'b' '1' ; 'c' '2' ; 'd' '3'}
so a = 'a' '0'
'b''1'
'c''2'
how can I convert the second column from string to number and should retain the cell array?

Respuesta aceptada

Ingrid
Ingrid el 11 de Jun. de 2015
a(:,2) = mat2cell(cellfun(@str2num,a(:,2)),ones(4,1),1)

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 11 de Jun. de 2015
a = { 'a' '0' ; 'b' '1' ; 'c' '2' ; 'd' '3'}
a(:,2)=cellfun(@str2double,a(:,2),'un',0)
  2 comentarios
Supraja Murali
Supraja Murali el 20 de Dic. de 2018
Can you explain what 'un' and '0' are in the answer above?
madhan ravi
madhan ravi el 20 de Dic. de 2018
un-> UniformOutput 0-> false

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings 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