How to make this string a = '(0 0 0)' into a double b = [0 0 0]?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Wictor Oliveira
el 5 de Ag. de 2022
Comentada: Walter Roberson
el 5 de Ag. de 2022
Suppose I don't know what are the number inside the a string, it could be:
a = '(12 2.8 1.22)' % each number is separated by a single space
which should then be:
b = [12 2.8 1.22]
0 comentarios
Respuesta aceptada
Kevin Holly
el 5 de Ag. de 2022
a = '(12 2.8 1.22)'
a = strrep(a,')',']');
a = strrep(a,'(','[');
b = str2num(a)
Más respuestas (1)
Fangjun Jiang
el 5 de Ag. de 2022
Editada: Fangjun Jiang
el 5 de Ag. de 2022
a = '(12 2.8 1.22)';
b=sscanf(a,'(%f %f %f)')
b=transpose(sscanf(a,'(%f %f %f)'))
2 comentarios
Ver también
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!