running time
古いコメントを表示
hi,
the running time of the following code is very long:
%%%%%%%%%%%%%%
for i=1:p
count=0;
for j=1:p
if mat(i,2)~=0
if mat(i,2)==mat(j,2)
mat(i,2)=0;
mat2(i,2)=i;
count=count+1;
x(i)=count;
end
end
end
end
%%%%%%%%%%%%%
where p=211000
are there anyway to make it faster?
thanks in advance
採用された回答
その他の回答 (1 件)
Daniel Shub
2011 年 10 月 19 日
Since mat(i, 2) will always equal mat(j, 2) when i is equal to j and you will always set mat(i, 2) to zero unless it is already equal to zero. I think at the end you have effectively done
mat(:, 2) = 0;
the mat2(i, 2) part is basically
mat2(:, 2) = 1:p;
mat2(mat(:, 2) == 0, 2) == 0;
This leaves the count part. You are looking for how many matches of mat(i,2) there are in mat(:, 2). I think you can do this with a hist function.
n = hist(mat(:, 2), unique(mat(:, 2));
The final step is putting the n's into x. I think there are probably quick ways of doing this.
2 件のコメント
huda nawaf
2011 年 10 月 19 日
Daniel Shub
2011 年 10 月 19 日
The inability to format code in a comment means I will not answer you here. I apologize since this isn't your fault. If Walter has answered your original question, then accept his question and ask a new one with your new code. If he hasn't, but has helped to refine your question, edit your question where you can add code markup. On a side note, trim your code as much as possible. I am not going to be able to get past the first line since I do not have ws.txt (nor do I want it).
カテゴリ
ヘルプ センター および File Exchange で Point Cloud Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!