Extracting only few numeric columns from alphanumeric .out file.
1 次查看(过去 30 天)
显示 更早的评论
Hello there,
After searching for 2 days I could not find the solution myself. I finally have to post the question here to seek help from experts.
I have an .out file from the simulation software which contains the text of few pages, then a numeric table, and then 1 page of text.
I m interested in the numeric table which has 13357 rows and 10 columns. The numeric table looks like below.
Till now, i had 3 files like this. I manually deleted the text above and below the .out file and then imported to matlab manually selecting the desired columns and saved it as a matrix. But now i will be having lots of files like this so i need an optimized script.
I would like to extract only the numeric values for 1st, 2nd and 7th colums only. The desired output values are below, which i did manually.
I am attaching the .out file also.
2 个评论
采纳的回答
Ameer Hamza
2020-4-8
try this
data = fileread('DJI3fq3.txt');
loc_nl = find(data==newline); % getting locations of all newlines
nl_double_nl = strfind(data, [newline newline]); % getting locations of all double newlines
loc_LOCATION = strfind(data, 'LOCATION'); % first column have title LOCATION
data_start = find(loc_nl > loc_LOCATION, 2); % 2nd newline after LOCATION is start of table data
data_start = loc_nl(data_start(2));
data_end = find(nl_double_nl > loc_LOCATION, 1); % 1st double newline after LOCATION is start of table data
data_end = nl_double_nl(data_end);
table_data = data(data_start+1:data_end-1); % extract data as char array
values = textscan(table_data, '%f%f%f%f%f%f%f%f%f%s'); % scan for numeric and string data
values = [num2cell([values{1:9}]) values{end}]; % cenvert to 2D cell array
T = cell2table(values); % convert to table
The values are stored in table T.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!