How to reduce execution time? "If" and "ismember" functions
3 views (last 30 days)
Show older comments
I have a big code, and when analyze profiler results one of the consuming steps is the comparisson "if ii== jj" and "if nn==1"... Is there any other way to do this so I can reduce time?
if true
if ii == jj
...
else
if nn==1
...
else
...
end
end
end
The other function that is consuming a lot of time is "ismember". Also anyone knows a better way?
if true
if ismember(nn,N1)
...
else
...
end
end
Thanks!!
3 Comments
Answers (1)
George Papazafeiropoulos
on 24 May 2014
To make ismember function faster, replace it with either ismembc or ismembc2 functions. ismembc returns an array of logical values while ismembc2 returns the index locations of the found members. More information about these can be found in the following:
https://www.mathworks.cn/matlabcentral/newsreader/view_thread/257728
Except for this, the "if ismember(nn,N1)" statement evaluates to true only if nn is a subset of N1. Since nn=1:10 and N1=1:5 it will always evaluate to false (the code after the above if statement will not be executed)
Since ii=1:13 and jj=1:13, the "if ii == jj" statement will evaluate always to true, preventing the next else section from execution.
0 Comments
See Also
Categories
Find more on Structures 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!