Transform char variable to matrix
Mostrar comentarios más antiguos
Hi, I have a cell variable that looks like this:

I'D like to know if there is a way to transform it into a matrix of this kind:
NewVar=[2 5; 2 3; 2 5];
Thanks
Respuesta aceptada
Más respuestas (2)
Stephen23
el 15 de Feb. de 2020
Efficient solution:
>> C = {'002,005';'002,003';'002,005'};
>> sscanf(sprintf('%s;',C{:}),'%f,%f;',[2,Inf]).'
ans =
2 5
2 3
2 5
Sindar
el 14 de Feb. de 2020
tmp={'002,005';'002,003';'002,005'};
NewVar=str2double(split(tmp,','))
2 comentarios
Guido Pozzi
el 14 de Feb. de 2020
Sindar
el 14 de Feb. de 2020
strsplit might work, but you might need to loop over cells
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!