How to read and arrange certain data in multiple text file?

Hi,
I need to arrange the data after post-proceesing in text file and need to arrange the data in certain order. I only need the numerical part of the data. Any suggestion to solve this problem?
Attached herewith 3 text file of the data.

 채택된 답변

Bhaskar R
Bhaskar R 2020년 3월 11일
FAM_data = readmatrix('FAM.txt');
FCC_data = readmatrix('FCC.txt');
FM2_data = readmatrix('FM2.txt');

댓글 수: 5

Thank you for your response.
If possible could you please share, how I can arrange this data in one data sheet?
Is it possible to extract only the 3 column of the text file?
Thank you in advance.!
% vertical concatanation
total_data = [FAM_data ;FCC_data ;FM2_data ];
total_data(:,[1, end]) = []; % remove first and coulmn as it has NaN values and only 0's
% OR horizantal concatanation
FAM_data(:,[1, end]) = []; % remove first and coulmn as it has NaN values and only 0's
FCC_data(:,[1, end]) = []; % remove first and coulmn as it has NaN values and only 0's
FM2_data(:,[1, end]) = []; % remove first and coulmn as it has NaN values and only 0's
total_data = [FAM_data ;FCC_data ;FM2_data ]; % vertical concatanation
% write data to excel file
writematrix(total_data, 'file_name.xlsx');
Thank you very much for your response. but another problem is, the output is in 600x4 array, but I need to get 200x12 array, which the data need to be arranged next to each other.
Could you please help me on this?
Thanks again !
This part works for you
FAM_data = readmatrix('FAM.txt');
FCC_data = readmatrix('FCC.txt');
FM2_data = readmatrix('FM2.txt');
% OR horizantal concatanation
FAM_data(:,1 = []; % remove first and coulmn as it has NaN values and only 0's
FCC_data(:,1) = []; % remove first and coulmn as it has NaN values and only 0's
FM2_data(:,1) = []; % remove first and coulmn as it has NaN values and only 0's
total_data = [FAM_data ;FCC_data ;FM2_data ]; % horizantal concatanation
% write data to excel file
writematrix(total_data, 'file_name.xlsx');
Its work!
This is the edted script I had used.
FAM_data = readmatrix('FAM.txt');
FCC_data = readmatrix('FCC.txt');
FM2_data = readmatrix('FM2.txt');
% OR horizantal concatanation
FAM_data(:,[1,2,end]) = []; % remove first,second and last column
FCC_data(:,[1,2,end]) = []; % remove first,second and last column
FM2_data(:,[1,2,end]) = []; % remove first,second and last column
total_data = [FAM_data,FCC_data,FM2_data]; % horizantal concatanation if vertical use (;) instead of (,)
% write data to excel file
writematrix(total_data, 'file_name.xlsx');

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

추가 답변 (1개)

Peter O
Peter O 2020년 3월 11일
편집: Peter O 2020년 3월 11일

0 개 추천

This seems like a good opportunity to leverage MATLAB's table datatype:
Use readtable() to import your data and writetable() to spit it out in the correct column ordering (adding/removing columns as needed. Within writetable, if you specify the name-value pair "WriteVariableNames" and false, the output file will not contain the headers.

댓글 수: 1

If possible could you please share the script? I already tried the readtable syntax but there is error. I need to arrange data in the three column of each text file in one sheet of certain order without the heading.
Thank you in advance for your respons.

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

카테고리

질문:

2020년 3월 11일

댓글:

2020년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by