These are the main coding practices and tools I always rely on.
- Vectorize (but sensibly).
- Use bsxfun in lieu of repmat where possible.
- When looping through an array, loop down columns to access memory in the same order that MATLAB stores the data in.
- Profile the code. I am often surprised about what is taking up the time.
- Pay attention to messages from the Code Analyzer.
- Use functions instead of scripts.
- Don't "poof" variables into any workspaces. Translation, don't use load without a left-hand side; avoid eval, evalin, and assignin.
- Use logical indexing instead of find.
- Avoid global variables.
- Don't use equality checks with floating point values.
本文分享了MATLAB编程中的一些核心实践和工具使用建议,包括合理利用向量化操作、避免使用某些效率较低的命令如eval和global变量等,还强调了性能分析及代码优化的重要性。
511

被折叠的 条评论
为什么被折叠?



