Extract column from text file
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
the cyclist
2023 年 6 月 12 日
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?
回答 (2 件)
Kautuk Raj
2023 年 6 月 13 日
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 件のコメント
Stephen23
2023 年 6 月 13 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!