Advice on a few bottlenecks in my code

According to the profiler, I have four lines of code taking up 99% of my CPU time.
if(statment)
pCond = (bold_Phi(k,2) <= data(thisIdx : idx, 7));
else
pCond = (data(thisIdx : idx, 7) <= bold_Phi(k,2));
end
IDY = find( (data(thisIdx : idx, 1) == -1) & (pCond) & (data(thisIdx : idx, 11) == bold_Phi(k,p + 10)) );
IDZ = find( (dV(thisIdx : idx, :) <= -bold_Phi(k,3)) & (pCond) & (sCond) );
where bold_Phi and data are 2D matrices and dV is a vector.
I dont think the time penalty is coming from the indexing as the following statement is very quick
~isnan(data(thisIdx : idx, 3));
anything obvious I have missed that will help me speed up these few statements?
thank you

4 件のコメント

Matt Kindig
Matt Kindig 2013 年 2 月 21 日
How large are bold_Phi and dV?
Matlab2010
Matlab2010 2013 年 2 月 22 日
dv = 1x500K. bold_Phi = 1E5 x 5E2 data = 12 x 500K.
Sean de Wolski
Sean de Wolski 2013 年 2 月 22 日
What is statement?
Matlab2010
Matlab2010 2013 年 2 月 22 日
編集済み: Matlab2010 2013 年 2 月 22 日
statement is a bool.

回答 (2 件)

Kye Taylor
Kye Taylor 2013 年 2 月 21 日

0 投票

If you don't need the actual indices, you can omit the find command to save time. In particular, notice that the following code blocks are equivalent but the first does not use find:
data = rand(1000,1);
isBig = data>0.5;
bigData = data(isBig);
and
data = rand(1000,1);
isBigIdx = find(data>0.5);
bigData2 = data(isBigIdx);

1 件のコメント

Matlab2010
Matlab2010 2013 年 2 月 22 日
this has helped, but only a little bit. Sped up by c. 10%.
Mark Whirdy
Mark Whirdy 2013 年 2 月 22 日
編集済み: Mark Whirdy 2013 年 2 月 22 日

0 投票

(Almost-) Never use the find() function!
I'd need to see the contents of the variables, but at first glance you can maybe just remove it altogether with same functionality?

この質問は閉じられています。

タグ

質問済み:

2013 年 2 月 21 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by