Extract column from text file
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, for my research project I have to analyze a certain output. The output gives a lot of measurements (also a lot of data I don't need), but I don't know how to extract the specific column of data that I do need. The data looks like this:
P1,R0,14:17:36.779,47,0.01421266,[-0.03077913; 0.3226232; -0.4286367],[0; 0; 0],[-0.4424625; 0.120887; -0.9627059],[-0.03836464; 0.5967162; 0.3170188],[-6.699989; -7.350024; 5.199996],50.48101,0.7456555,0,0,0,-5.2,0
P0,R0,14:17:36.823,47,0.01403595,[-0.03077913; 0.3226232; -0.4286367],[0; 0; 0],[-0.4424625; 0.120887; -0.9627059],[-0.03836464; 0.5967162; 0.3170188],[-6.699989; -7.350024; 5.199996],50.48101,0.7456555,0.08738,0.6293842,17.97661,-5.2,0
But I only need the first number between brackets (value -0.03077913 here). How do I do this?
2 commentaires
the cyclist
le 12 Juin 2023
The best method will depend on exactly what format of file you have. (For example, is it Excel, a CSV, etc.?) Can you upload the file (using the paper clip icon from the INSERT area of the toolbar), or at least a few representative lines?
Réponses (2)
Kautuk Raj
le 13 Juin 2023
To extract the first number between the brackets in the data provided, we can use regular expressions in MATLAB.
This regular expression pattern \[([-0-9\.]+);([-0-9\.]+);([-0-9\.]+)\] will match the three numbers between the brackets and captures them in separate groups.
0 commentaires
Stephen23
le 13 Juin 2023
Fake data (you would use FILEREAD):
S = sprintf('%s\n','P1,R0,14:17:36.779,47,0.01421266,[-0.03077913; 0.3226232; -0.4286367],[0; 0; 0],[-0.4424625; 0.120887; -0.9627059],[-0.03836464; 0.5967162; 0.3170188],[-6.699989; -7.350024; 5.199996],50.48101,0.7456555,0,0,0,-5.2,0','P0,R0,14:17:36.823,47,0.01403595,[-0.03077913; 0.3226232; -0.4286367],[0; 0; 0],[-0.4424625; 0.120887; -0.9627059],[-0.03836464; 0.5967162; 0.3170188],[-6.699989; -7.350024; 5.199996],50.48101,0.7456555,0.08738,0.6293842,17.97661,-5.2,0')
C = regexp(S,'(?<=\[)(-|+)?\d+\.?\d*','match')
V = str2double(C)
0 commentaires
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!