Indexing parts of a string that occur in every x characters

3 visualizaciones (últimos 30 días)
I have a string of data that goes on for a while. I want to index a certain value that occurs after the same number of characters because of the way the data is set up. Here's the string:
'GRID* 5250001 5200000 0.730198500E+02-0.177000000E+03* -0.512716000E+02 5200000 0 0GRID* 5250002 5200000 0.730198500E+02-0.176250000E+03* -0.512716000E+02 5200000 0 0...'
Say I want to extract the value after it says 'GRID*' every time. I want to write something to start indexing at the 17th character, extract the following 8 characters, then repeat the same process again 144 characters later to get the value next to where it says 'GRID*' for the second time, all the way until the end of the string. I thought it would be simple indexing, but I can't figure it out. Thanks in advance!

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Jun. de 2022
convert the string to char, reshape to 144 rows, extract row 17:17+8-1, all columns. You might want to transpose the result from columns to row.
  3 comentarios
Zain
Zain el 20 de Jun. de 2022
I'm not sure this method will work since each data cell is separated by a different number of characters, although it doesn't look that way. Some are 8 characters long and some are 16 characters long
Walter Roberson
Walter Roberson el 21 de Jun. de 2022
If there is a fixed separation between GRID* then reshaping should work. Extract the maximum number of characters per entry, as columns, such as 17:17+16-1. Transpose, string() or cellstr() and post process to decide the proper size for each entry.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by