필터 지우기
필터 지우기

Remove the header from multiple text files

조회 수: 5 (최근 30일)
Majid Mohamod
Majid Mohamod 2017년 5월 18일
댓글: Star Strider 2017년 5월 18일
Hi all..
I use the following code to export multiple columns in excel file to multiple text files (each column export as text file).
Walter Roberson wrote me the following code:
data = readtable('YourFileName.xls');
varnames = data.Properties.VariableNames;
for col = 1 : size(data, 2)
thisvar = varnames{col};
filename = sprintf('split_%s.txt', thisvar);
writetable( data(:,col), filename );
end
It works very well, but the only problem is each text file gets a header X1. Can I use this script without having header? The following screenshot explain more about the problem:

채택된 답변

Star Strider
Star Strider 2017년 5월 18일
Consider using xlsread. It will separate the numeric values from the headers. You can still have access to the headers (and other non-numeric data) as well as the raw data by requesting 2 or 3 outputs from xlsread instead of only the first output.
  댓글 수: 2
Majid Mohamod
Majid Mohamod 2017년 5월 18일
Please, Could you explain more in this regard. I still beginner in Matlab!
Star Strider
Star Strider 2017년 5월 18일
I would do something like this:
[numeric_data, string_data, raw_output] = xlsread('YourFileName.xls');
The ‘numeric_data’ array will have your numeric data (possibly with NaN values in the first row that you can easily eliminate) as a double array. The headers (and other string data) will be in the ‘string_data’ output, and the entire contents of the file (as a cell array) will be in the ‘raw_output’ variable.
See if that does what you want.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by