running time problem in matlab

2 ビュー (過去 30 日間)
f4r3in
f4r3in 2019 年 11 月 8 日
コメント済み: f4r3in 2019 年 11 月 8 日
again I have running time problem.
I want to write a script that find dublicate rows and keep one of them and sum probability of them then write that probability in the 2nd column next to that row.
for example:
I want to change this input
12 0.02
16 0.04
20 0.01
20 0.015
20 0.01
30 0.05
to this :
12 0.02
16 0.04
20 0.035
30 0.05
I write below script to do this action but it takes too long to do this. (also my friend do this action by this scrip in a few seconds (we have same laptops) )
COPT=sortrows(COPT);
%till here program runs in 0.4 sec
%but from here to end takes too long to run this program.
u=1;
while u<=size(COPT,1)-1
if COPT(u,1)==COPT(u+1,1)
COPT(u,2)= COPT(u,2)+COPT(u+1,2);
COPT(u+1,:)=[];
end
u=u+1;
end
I also upload my input ("COPT.mat") here if you want to use it. (I know my input is huge but as I said my friend run this script in only a few seconds)
what should I do???

回答 (1 件)

Steven Lord
Steven Lord 2019 年 11 月 8 日
Take a look at groupsummary.
  3 件のコメント
Steven Lord
Steven Lord 2019 年 11 月 8 日
groupsummary is a function introduced in MATLAB in release R2018a. If you're using release R2018a or later, you can see what it does and how to use it by reading its documentation page.
doc groupsummary
If you're using an older release, search the MathWorks website for the word "groupsummary." If it looks like it will be useful for your application and you are willing to upgrade to release R2018a or later, upgrade and you'll be able to use it.
f4r3in
f4r3in 2019 年 11 月 8 日
Thanks for answering but I use matlab 2016a and I look at groupsummary, it doesn't do what I want. I write the script that I want but it takes too time to run. I write my problem here to find faster way to do my job.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDiscrete Fourier and Cosine Transforms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by