How can I convert a cell array with values {'S101' 'S102'},to a double array?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Bubblesjinx
el 21 de Ag. de 2018
Comentada: Bubblesjinx
el 21 de Ag. de 2018
events = {'S100';'S102';'S103';'S101'}
3 comentarios
John D'Errico
el 21 de Ag. de 2018
A double array of what? The numbers [101, 102]? Or, perhaps the values stored inside the variables S101, S012, etc? Or maybe even the ascii representation of those characters. The point is, 'S101' is itself not a number. It is just a string of characters. In your eyes, it may represent something, but only you know the context of what you want to see.
Respuesta aceptada
Stephen23
el 21 de Ag. de 2018
Editada: Stephen23
el 21 de Ag. de 2018
Making some assumptions:
>> events = {'S100';'S102';'S103';'S101'};
>> str2double(strrep(events,'S','')) % easy
ans =
100
102
103
101
>> sscanf(sprintf('%s\v',events{:}),'S%d\v') % probably more efficient
ans =
100
102
103
101
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures 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!