フィルターのクリア

code is running too long, help me to optimize it

7 ビュー (過去 30 日間)
Asliddin Komilov
Asliddin Komilov 2019 年 2 月 26 日
編集済み: Asliddin Komilov 2019 年 2 月 27 日
I have written a code, it runs slow. I don't know if it is because of the code or just it should take so long because of the number of loops and calculations.
can you help me to check/improve it please.
  2 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 26 日
upload your code
Asliddin Komilov
Asliddin Komilov 2019 年 2 月 26 日
here it is

サインインしてコメントする。

採用された回答

Jan
Jan 2019 年 2 月 26 日
Start with inserting the code in a function, instead of using a script and try to use clear all to kill everything, which might be out of sight. This is a massive waste of time only.
Then mark the code with Ctrl-a and press Ctrl-i to apply a proper auto-indentation. This does not make the code faster, but much easier to debug. A lot of meaningful comments are essential also: Without it other readers cannot understand the purpose of the code- or you in some months. If I should work with this code, I'd give up immediately, because it is impossible to debug blocks like this:
Tc(jj) = Tc(jj-1)+dTc(jj-1);
Tt(jj)=Tt(jj-1)+dTt(jj-1);
Twout(jj)=Twout(jj-1)+dTwout(jj-1);
Tw(jj)=Tw(jj-1)+dTw(jj-1);
Tg1(jj) = Tg1(jj-1)+dTg1(jj-1);
Tadt(jj) = Tadt(jj-1)+dTadt(jj-1);
Tadb(jj) = Tadb(jj-1)+dTadb(jj-1);
t(jj)=t(jj-1)+1;
Ub(jj)=Ub(jj-1);
For the actual problem use the profiler to find the bottleneck: Which line needs the most processing time? It is not worth to optimze some code, which takes a few percent of the total time only.
It is not called often in your code, but remember that 10.^-5 is an expensive power operation, while 1e-5 is a cheap constant.
  1 件のコメント
Asliddin Komilov
Asliddin Komilov 2019 年 2 月 27 日
編集済み: Asliddin Komilov 2019 年 2 月 27 日
Thank you very much, I will make it function after I complete it. I used the profiler as you have suggested. The main problem is the Xsteam function and lines like Ex(Ex<0)=0, could you share some ideas on this?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by