Long runtime when producing the graph
4 次查看(过去 30 天)
显示 更早的评论
Hi. I’m new here.
I’m working with importing data from MS Excel and make it in a almost a thousand lines of coding. Because I directly use data from MS Excel. Normally it takes up to 15 minute to produce the graph. Currently I’m using processor i5, RAM 12gb and hdd 1tb. Anyone can suggest for me what best way to cut down the time producing the graph? Maybe upgrade to ssd or upgrade another RAM? Or should I transfer everything in table form and not to use in MS Excel anymore?
Thank you in advanced.
5 个评论
Peter O
2020-8-29
Mario's suggestion on the profiler command will help you a lot.
A couple tips for common issues with I/O to look for:
- A FOR loop that repeatedly calls an import function. If you're accessing a couple thousand rows and you're importing one row at a time, you're opening and closing a file on disk each time the loop executes. It's much more efficient to access the file on disk once, read everything into memory, and manipulate from there. At a minimum, you want to minimize the open/close operations. MATLAB's I/O functions have a lot of flexibility on how to get data out of a file, so check out their documentation.
- If you haven't already, take a look at how the Import Data function is structured. Use the command from the toolbar on one of your spreadsheets and then hit the "Generate Code" dropdown to make a script or function. It might help you improve your programmatic file access method.
- Preallocation of data array space. The profiler will catch this, but if you're reading into memory and growing the array each time, then you're asking the computer to search for larger and larger chunks of memory each time, rather than just reserve one big chunk once.
And if the import is fast, it might be in the plot, though I think that's a little less likely, but with a lot of internal graphics objects to render, the plot tools can slow down. Are you trying to trying to put a million points on the chart? Or a couple hundred individual lines?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!