How can I code this more effectively regarding running time?
이전 댓글 표시
I have this data: 'randoms' (cell of cells array size 4319*100) that is:
(4319 columns)
(4319 columns) my code runs, but it takes 7 min! is there any way to make it more efficient?
this is my code:
for j=1:length(randoms)
all_100=randoms{j};
for l=1:100
randi=all_100{l};
dimers = dimercount(randi);
for k=1:16
x=cell2mat(struct2cell(dimers));
B{l}=x.';
C=cell2mat(B);
S(j)=mean(C(:,k));
end
end
end
Thank you!!!
댓글 수: 1
the cyclist
2022년 4월 9일
Generic advice would be to use the profile command, to see which lines of code are taking the most time, and focusing on those.
답변 (1개)
Jan
2022년 4월 9일
0 개 추천
It is hard to impossible to optimize code without having the complete code and the input. You have to guess too many details:
- Are B and S pre-allocated?
- Why do you overwrite S(j) 1600 times?
- What is the purpose of struct2cell->cell2mat->cell->cell2mat? This looks far to complicated. Why don't you work with numerical arrays directly?
- Why do you create the complete matrix C, if you need the k'th column only?
카테고리
도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!