How to Split excel file using matlab

2 ビュー (過去 30 日間)
Jerry Paul
Jerry Paul 2017 年 1 月 26 日
コメント済み: dbmn 2017 年 1 月 27 日
Hello,
I have a 62000 row excel file that I want to split to 61 files. Can I do this with MatLAB. The content is a single column with numbers (like .605785). Kindly help.
Thanks

回答 (2 件)

dbmn
dbmn 2017 年 1 月 26 日
Hi,
you should be able to build something like that, using the following commands.
1. reading your data
your_data= xlsread(filename);
2. split your array
len = ceil(numel(your_data)/num_files);
for k=1:num_files
tmp = your_data([1:len]+len*k);
end
alternatively use reshape in this step
3. saving the excel (preferably in the loop)
xlswrite(filename,tmp)
maybe you want wo use csvread/csvwrite instead
this should get started!

Jerry Paul
Jerry Paul 2017 年 1 月 27 日
Thanks for your reply! I am new to MatLAB and now after executing the code its showing 'Index exceeds matrix dimensions.' Any help! Thank you
  1 件のコメント
dbmn
dbmn 2017 年 1 月 27 日
You are right. I was slightly sloppy on the indices (and didn't test my code). The last iteration is actually shorter (no 1017 elements but less)
% All the loops (but not the last one)
for k=0:num_files-2
tmp = your_data([1:len]+len*k);
end
% And now the last iteration (this one is only 981 elements long)
tmp = your_data(len*(num_files-1):end);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by