matlab 写excel 慢_在MATLAB中缓慢的xlsread

针对MATLAB程序中运行缓慢的xlsread操作,作者进行了性能分析。由于需要进行数十万次的模拟运行,因此寻找更快的Excel文件读取方法至关重要。尝试将xlsread设置为基本模式并减少文件调用次数,下一步计划优化xlswrite。虽然使用dlmread写入CSV文件速度很快,但为了保持Excel工作表的便利性,作者必须继续使用.xls格式。解决方案包括考虑并行计算,如利用并行计算工具箱或多个MATLAB实例来分别处理读取、模拟和写入过程,以提高效率。
摘要由CSDN通过智能技术生成

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).

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. :|

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.

解决方案

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:

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.

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值