How to get [1 0 1 0] from '1010'

1 visualización (últimos 30 días)
Durga Lal Shrestha
Durga Lal Shrestha el 29 de Sept. de 2014
Comentada: Durga Lal Shrestha el 30 de Sept. de 2014
Is there any built-in function or easiest way to get [1 0 1 0] from '1010' (character array)?
I have used for loop, but is there any other way to get the results?
str = '1010';
vec = zeros(length(str),1);
for i=1:length(str)
vec(i) = str2double(str(i));
end

Respuesta aceptada

Stephen23
Stephen23 el 29 de Sept. de 2014
Editada: Stephen23 el 29 de Sept. de 2014
Try this:
'1010' - '0'
or equivalently:
'1010' - 48

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 29 de Sept. de 2014
str2double(regexp('1010','\d','match'))

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by