Split Data in Character Array into Matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Vanessa Yau
el 24 de Mayo de 2020
Comentada: Vanessa Yau
el 26 de Mayo de 2020
I currently have a character array (~ 50000 x 1) with data "DD-MM-YY 1000 NaN NaN NaN 0.200 0.300" all in one cell, and I want to split the characters into a matrix with cells for each of the colums (i.e. col1= "DD-MM-YY" col2= 1000, etc.). However, the data in some rows are not perfectly spaced/aligned with other rows because the length of the data may be > than the length of NaN (i.e. "DD-MM-YY 1000 0.111 NaN 0.2002 0.200 0.300 ") so I cannot filter them based on character location. There is extra spacing at the end to account for this shifting (each has a length of 80). Any ideas on how I could split the data, or even how to align all the data columns?
Thanks so much!
2 comentarios
Respuesta aceptada
Walter Roberson
el 25 de Mayo de 2020
temp = regexp( cellstr(sample), '"(?<date>)[^"])"\s+(?<col2>\S+)\s+(?<col3>\S+)\s+(?<col3>\S+)\s+(?<col4>\S+)\s+(?<col5>\S+)\s+(?<col6>\S+)', 'names', 'once');
parts = vertcat(temp{:});
dates = datetime({parts.date}, 'Format', 'MMM-dd-yyyy HH:mm:ss');
col2s = str2double({parts.col2});
col3s = str2double({parts.col3});
col4s = str2double({parts.col4});
col5s = str2double({parts.col5});
col6s = str2double({parts.col6});
Más respuestas (0)
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices 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!