필터 지우기
필터 지우기

Splitting an excel file using matlab

조회 수: 24 (최근 30일)
joseph Frank
joseph Frank 2011년 7월 18일
Hi,
I have a 900,000 row excel file that I want to split to 900 files. I am wondering if i can do this with matlab. the content is a single column with strings like :US000305AA00. Kindly advise otherwise i have to do it manually which is very time consuming.

채택된 답변

Rick Rosson
Rick Rosson 2011년 7월 18일
Yes, you can do this task with MATLAB. Please try the following:
inputFile = 'myfile';
A = xlsread([ inputFile '.xlsx' ]);
M = 1000;
N = 900;
for k = 0:N-1
outputFile = [ inputFile num2str(k+1,'%03i') '.xlsx' ];
xlswrite(outputFile,A(M*k+(0:M-1)+1));
end
I have tested this code for M = 20 and N = 10, and it works just fine. I suspect, however, that it will take a long time to run for a file containing 900,000 numbers.
HTH.
Rick
  댓글 수: 8
Rick Rosson
Rick Rosson 2011년 7월 18일
Hi Joseph,
I have given you everything you need to solve this problem. I have tested my code, and it works just fine. Please try to get it to work on your machine with your file. If you assign the correct values to the parameters, use the correct file name and extension, and make sure the file is available on the MATLAB path, it should work.
joseph Frank
joseph Frank 2011년 7월 18일
I imported the file manually using the import wizard and it is working well. Thanks Rick but still I can't figure out why A was empty given that my xlsx file name was ISIN.xlsx

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 7월 18일
Is the file .csv format or .xls or .xlsx format?
Does the header of the file need to be repeated for each new file?
Is the output fixed at 900 files, or is it fixed at 1000 rows per file?
Probably you probably do not need a lot more than this FAQ
but if your file does happen to be .csv and you do not need to repeat the header line there might be easier alternatives (especially if you are using MacOS or Linux)
  댓글 수: 1
joseph Frank
joseph Frank 2011년 7월 18일
the file is .xlsx format without headers. Each file should contain 1000 observations.so in total I should have 900 files.

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

카테고리

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