フィルターのクリア

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 Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by