Indexing parts of a string that occur in every x characters
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zain
el 20 de Jun. de 2022
Comentada: Walter Roberson
el 21 de Jun. de 2022
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!
0 comentarios
Respuesta aceptada
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
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.
Más respuestas (0)
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!