Check for specific information in a string from a table

8 vues (au cours des 30 derniers jours)
Luke Swift
Luke Swift le 20 Déc 2019
Commenté : J. Alex Lee le 21 Déc 2019
I imported a text file into matlab and all the data is stored in one column.
lines 24-32 represent one set of data. Line 30-32 have one set of information: DOCUMENT TOTALS: $5,810.00 $0.00 $5,810.00. I only need the data if the "A1" term is a specific term (i.e. A12, A232, B343, D343F). There are some terms there that would signal that I don't need that data set (i.e. C232, C34F) The term will be a letter followed by a number 1-999 and can possibly have another letter after. Do you know any way to sort this information better, or at least be able to check each line for the specified term above. I know I could use a case function or an if statement to check if the term once I have it. I just don't know how to check that specific term. Also I should note that the file has 14,290 rows and 1 column, so if i can get information into more columns, that would be great.
  5 commentaires
Luke Swift
Luke Swift le 20 Déc 2019
I would but im not allowed to. I think I can use strfind() to check for what I need thought. Thanks for the help.
J. Alex Lee
J. Alex Lee le 21 Déc 2019
Based on the screenshot, I don't think readtable would work because the data doesn't appear tabular in nature. I would probably use a combination of
  1. fileread() to read in the entire file as a character vector, split on keywords that delimit chunks (DOCUMENT TOTALS)
  2. textscan() to parse that chunk
or, if the number of lines of each chunk is always consistent, read the file line-by-line using fgetl() or something like that.
If the data is confidential and you still need external help, mock up a gibberish file with the essential features of the formatting and share that.

Connectez-vous pour commenter.

Réponses (1)

J. Alex Lee
J. Alex Lee le 21 Déc 2019
Assuming that parsing your text file to mine the data is a separate and solved problem, your question about identifying the string pattern may be solved by using ismember()
AllowedTags = {'A12','A232','D343','D343F'}
isAllowed = ismember('A1',AllowedTags)

Community Treasure Hunt

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

Start Hunting!

Translated by