필터 지우기
필터 지우기

Extracting only few numeric columns from alphanumeric .out file.

조회 수: 2 (최근 30일)
Wajahat Farrukh
Wajahat Farrukh 2020년 4월 8일
댓글: Ameer Hamza 2020년 4월 9일
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
Ameer Hamza 2020년 4월 8일
Does the outfile will always have the same number of header and footer rows?
Wajahat Farrukh
Wajahat Farrukh 2020년 4월 8일
The header and footer rows are not always the same.
but it always has "THETA", "PHI" etc on top and an empty row after the table is finished.
after empty row, there is a line statement which is always same.

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
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.
  댓글 수: 2
Wajahat Farrukh
Wajahat Farrukh 2020년 4월 9일
exactly what i was looking for. Thanks alot brother.
i just made this file as a function to use in my scripts :)
very quick and to the point solution.
Ameer Hamza
Ameer Hamza 2020년 4월 9일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by