Extracting only few numeric columns from alphanumeric .out file.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Wajahat Farrukh
el 8 de Abr. de 2020
Comentada: Ameer Hamza
el 9 de Abr. de 2020
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 comentarios
Ameer Hamza
el 8 de Abr. de 2020
Does the outfile will always have the same number of header and footer rows?
Respuesta aceptada
Ameer Hamza
el 8 de Abr. de 2020
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.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!