While loop & time consumption

9 ビュー (過去 30 日間)
Maria Andersson
Maria Andersson 2014 年 2 月 4 日
編集済み: Maria Andersson 2014 年 2 月 5 日
Hi!
I am using a while loop and I am actually not sure why it takes very long time for matlab to proceed the code without generating an answer. It might be that I have missed something in the code that I'm not sure about.
So my question is: Does the code contain errors that I am not aware of? and if not, what can be done so that it will go faster to proceed the whole process!
would really appreciate some feedback and help.
  2 件のコメント
Robert Cumming
Robert Cumming 2014 年 2 月 4 日
help profile
use this to profile the code, it will show you which lines are taking the most time.
Amit
Amit 2014 年 2 月 4 日
The first question is what does the function speed do. Because speed's output is v which controls the while loop

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

採用された回答

Shivaputra Narke
Shivaputra Narke 2014 年 2 月 4 日
I guess you have defined some functions like acceleration,speed. May be these functions take too much of time.
Best way to analyse your code is debugging.Use break points and go step wise to find where you code is consuming too much of time.
If you want to save time then avoid using loops. Instead try to learn and use vectorization.
  2 件のコメント
Maria Andersson
Maria Andersson 2014 年 2 月 4 日
Thank you for your feedback, I have used the debugger and it seems like that the equatoins is not even considering that time (t) changes until v=-20 m/s. That leads to that heightvektor2 and speedvektor 2 contains only one value for all rows. All the steps goes quickly until the plot function, that is where it becomes slow
Shivaputra Narke
Shivaputra Narke 2014 年 2 月 4 日
So what is the length of 't' at the time of plot?

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

その他の回答 (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