Speeding up IF and comparisons whithin a loop

12 views (last 30 days)
I have a function which is being run inside a loop.
The line consuming more time is an IF condition. X is not even a vector, just a single value.
if (ge(X, 0.557893) && le(X,1))
....
end
(The condition is equivalent to X>= 0.557893 && X<=1.)
Do you know why? Is there any equivalent and faster way to do it?
IF.PNG

Accepted Answer

Jan
Jan on 30 Mar 2019
Do not take the output of the profiler too literally. If this is the first access to the value of X, it might be the time for copying the value from the slow RAM to the fast processor cache. Only if you consider the surrounding code, the meaning of the profiled times become more or less meaningful.
The general idea would be to vectorized the code, I guess.

More Answers (0)

Categories

Find more on Performance and Memory in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!