How could I accelerate m-file code?
1 回表示 (過去 30 日間)
古いコメントを表示
I'm trying to implement model predictive control to DC motor. MPC code was implemented in scripts, without toolboxes, and DC motor model was identified by nlarx method. I need that control loop run at 0.1 seconds, but it is running average at 0.5 seconds. I'm using preallocated variables and parfor functions to accelerate the code. I could use discrete equation instead sim function, but I dont know how to get explicit equation from idnlarx model.
How could I accelerate even more the m-file code?
0 件のコメント
回答 (1 件)
Jan
2017 年 2 月 7 日
Do not use
warning off; clear all; close all; clc;
because clear all removes all loaded function from the RAM and reloading the files from the slow hard disk wastes a lot of time.
Calling WMIC through system is time consuming also and as far as I cen see, this is applied to the same Matlab session all the time.
Matlab's JIT acceleration works only for lines, which contain one command. At least this was the situation in the time, when this feature was documented. Although modern Matlab versions might not suffer from this limitation, having one command per line only improves the readability.
If you are sure, that all variables are pre-allocated properly, then I do not have more general methods. Use the profiler to find the bottleneck of the code, because it is not worth to optimize a line, which takes 0.1% of the processing time only: you can reduce the runtime by 0.1% only, if you can accelerate this line by a factor of even Infinity.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Simulation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!