Less time consuming substitution for if conditional
2 ビュー (過去 30 日間)
古いコメントを表示
I have a long script with lots of if conditional and it takes a long time to run the code. Any suggestion to make it efficient for example a less time consuming substitution for if conditional.
for example:
if rim==core
rim=rim+1;
end
Can I change above if conditional to shorter script?
0 件のコメント
回答 (2 件)
John D'Errico
2019 年 9 月 29 日
I think you are focusing on the wrong things. This is NOT a slow operation.
Very likely, this is part of a large, inefficiently written code, where you are doing tests like that for the wrong reason. But we don't see your code.
So the first thing you should do is learn to use the profiler. It will tell you what lines of code are taking a lot of time. Then focus on them.
As importantly though, my guess is as I said, that your entire code is written inefficiently. You need to learn to use vectorized operations, where operations will apply to an entire set of values at once. That is how you will find significant speed boosts, NOT by hoping to save a hundreth of a millisecond on a simple test like that.
参考
カテゴリ
Help Center および File Exchange で Manual Performance Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!