How to get elapsed time of a code in matlab ?

1 回表示 (過去 30 日間)
Adnan Hayat
Adnan Hayat 2022 年 8 月 1 日
コメント済み: Walter Roberson 2022 年 8 月 1 日
Hello,
I run a code of two variables which does not contain any function. I simply run a partial differential equation using forward difference farmula inside two loops of time and space. I use 'tic' and 'toc' to get the elapsed time of the code at the end. But I need this time in advance as my code takes hours to give result. Can I get the expected elapsed time in advance ?
  4 件のコメント
dpb
dpb 2022 年 8 月 1 日
Just turn off any power-off settings and, of course, be sure the machine is on an UPS so it doesn't lose power.
Then add code to the end of the process that notifies you by <SendTextMessageFromMatlab> when it's done.
As far as predicting how long that will be other than extremely crudely, that's <Merlin>'s arena...
Walter Roberson
Walter Roberson 2022 年 8 月 1 日
How long is it going to take to clean your garage? You are not permitted to use your records of how long it has taken you in the past to clean garages of similar size, and you are not permitted to clean a fraction of the garage and use the timing to estimate the total time.

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

回答 (2 件)

John D'Errico
John D'Errico 2022 年 8 月 1 日
Sorry, but no.
A prediction of the time required for some arbitrary piece of code will never happen. It cannot happen. Well, not true. If you run the code in advance, EXACTLY as you will call it, then the predicted time is just the time it took the last time you ran that same problem.
You can run smaller problems, then figure out how the problem size will extrapolate up, but even that is rarely something you can predict at all well.

Walter Roberson
Walter Roberson 2022 年 8 月 1 日

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by