Writing a loop to import and save multiple excel sheets onto matlab individually

3 views (last 30 days)
I have 300 excel sheets with data with 3 rows and variable lengths. I would really appreciate it if anyone knows how I can import these and save them with the same name as the excel sheet that each matrix corresponds to. I can pull up the data using this: xlsread('firstdataset.xlsx','0001','B7:E100');
However, I need to make a for loop such that the sheet goes from 0001 to 0320 (and the zeros need to be there before the number). I also would like to eliminate rows of zeros for matrices that have shorter lengths.
I would really appreciate any help. Thank you!

Accepted Answer

Amna
Amna on 24 Jun 2014
The code ended up being very simple and I thought I would share it in case anyone wanted it:
n=200; for i=1:n k=sprintf('%04d',i); a{i}=xlsread('firstdataset.xlsx',k,'C1:E75'); end
  1 Comment
Image Analyst
Image Analyst on 24 Jun 2014
That will take a very long time for 300 workbooks. If you want to do it faster, use ActiveX so that you only have to open Excel once and close it once rather than 300 times. See attached demo.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!