Hi, i need some more help with effeciency. This following code is running very slowly (took over 800 seconds for one of my data sets)
for l= 1:listsize;
for m = 1:length(peak_loc2{l});
counter2 =1;
while peak_loc2{l}(m)~= mymatrix2(1, counter2)
counter2=counter2+1;
end
mymatrix2(2,counter2) = mymatrix2(2,counter2) +1;
end
end
here listsize is 271 peak_loc2 is a list of cell, around 100 cells, each containing anywhere from 2 to a few hundred variables
mymatrix2 is a 2X3000s that list all the peaks in peak_loc2, and non-recurring

 채택된 답변

Sean de Wolski
Sean de Wolski 2011년 12월 7일

0 개 추천

you can replace the while loop with
counter2 = find(mymatrix(1,:)==peak_loc2{1}(m),1,'first')

댓글 수: 5

Andy
Andy 2011년 12월 7일
for l= 1:listsize;
for m = 1:length(peak_loc2{l});
counter2 =1;
counter2 = find(mymatrix(1,:)==peak_loc2{1}(m),1,'first')
counter2=counter2+1;
mymatrix2(2,counter2) = mymatrix2(2,counter2) +1;
end
end
like that?
Andy
Andy 2011년 12월 7일
thanks it worked well
Andy
Andy 2011년 12월 7일
hey, i ran both my version and your version, turns out my version gives over 3000 variables, while the one you gave me is faster by a lot, it only gave me a bit over 100 variables, why is this?
Sean de Wolski
Sean de Wolski 2011년 12월 7일
If you have over 3000 variables there's something we're not seeing. Perhaps you could post a sample matrix (small) or a *.mat file to somewhere.
Andy
Andy 2011년 12월 7일
it turns out it still graphs it properly the way i wanted, so its fine thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

질문:

2011년 12월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by