How could I accelerate m-file code?

조회 수: 1 (최근 30일)
Douglas Freire
Douglas Freire 2017년 2월 7일
답변: Jan 2017년 2월 7일
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?

답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Simulation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by