Indexing parts of a string that occur in every x characters
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2022-6-20
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 个评论
Walter Roberson
2022-6-21
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!