필터 지우기
필터 지우기

Export excel columns to multiple text files

조회 수: 2 (최근 30일)
Majid Mohamod
Majid Mohamod 2017년 5월 16일
편집: Majid Mohamod 2017년 5월 17일
I have excel file with multiple columns. I want to export each column to separated text file. So, I've 1650 columns and the output should be 1650 text file. There is anyway to do it in Matlab or any other method?
Thank you in advance! Majid

답변 (1개)

KSSV
KSSV 2017년 5월 17일
You should be reading data from excel file using xlsread. Check the below code.
% data = xlsread('your excel file') ;
% rows = size(data,1) ;
rows = 100 ;
data = rand(rows,1650) ;
% run a loop to save each column into text file
for i = 1:1650
filename = strcat(num2str(i),'.txt') ;
data_col = data(:,i) ;
save(filename,'data_col','-ascii') ;
end
But still, I am surprised why you want each column into a text file though you have them in excel.
  댓글 수: 2
Majid Mohamod
Majid Mohamod 2017년 5월 17일
I am preparing text files to be use in ArcSWAT. ArcSWAT read only a specific format of text files. I ran your code and it works. The problem is the output files is really different from the data on excel file!! This is the screenshot:
Majid Mohamod
Majid Mohamod 2017년 5월 17일
편집: Majid Mohamod 2017년 5월 17일
On other hand, Walter Roberson had helped me to build a script. He also did the script for me of "Export excel columns to multiple text files" but it has simple problem which is the output has headers "x_1, x_2.......x_n). I'm including the screenshot of the output files here:
This is Walter Roberson's script:
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
The link of the answer is here
Please, could help to modify this script so can do the purpose?
Thanks, Majid

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by