OrangeRind
OrangeRind

Reputation: 4818

Slow xlsread in MATLAB

Here is the result of a profiled simulation run of my MATLAB program. I need to run this simulation several hundred thousand times (~100,000 times).

The abnormally slow xlsread

Thus I need a faster way to read the Excel file.

Specifications: The Excel file is of 10000x2 cells and each simulation run is reading one such sheet each from 5 separate Excel files.

UPDATE: I put the xlsread in basic mode and also reduced the number of calls by combining my input into a single file. Next target is xlswrite now. Ah, that sinking feeling. :|

Updated Profile Summary

NOTE: Although writing to a CSV file using dlmread is very fast (around 20 times), I need to use the comfort of separate sheets that an .xls file provides.

Upvotes: 3

Views: 5906

Answers (1)

Ashish Uthama
Ashish Uthama

Reputation: 1331

I don't think you would be able to wring much out of xlswrite if you need Excel sheets as the output.

How about parallelizing?

Do you have access to the parallel computing toolbox? Or maybe you can run two instances of MATLAB if your box supports it. If so, you could consider two approaches:

  1. Have the first process do the xlsread part, the simulation part and then write to mat files/plain binary/CSV, whatever is the fastest while preserving your data integrity. Have another process convert the matfiles/intermediate data files into Excel using xlswrite.

  2. Have N MATLAB instances/workers (N depends on your physical machine capacity). Parallelize the whole read-process-write part across N workers. Note, I am not sure how Excel would scale when called by N workers! (xlswrite uses activeX/MS Excel to write the data).

As any parallel approach, your mileage will vary on the complexity of the simulation vs. required file I/O and its performance.

Upvotes: 1

Related Questions