running time problem in matlab
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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???
0 comentarios
Respuestas (1)
Steven Lord
el 8 de Nov. de 2019
Take a look at groupsummary.
3 comentarios
Steven Lord
el 8 de Nov. de 2019
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.
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!