Speeding up IF and comparisons whithin a loop

11 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2019-3-30
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by