How can I reduce the execution time when calculating mean values within a 3 times loop?
Mostrar comentarios más antiguos
Deal all, good morning!
I would like to ask your help regarding to a computational problem that I have. I'm trying to calculate 10 minutes values on a daily basis. So my original file is something like this: [year DoY time(minutes) value]
2010 132 150 1.52
2010 132 151 2.5
2010 132 153 3.4
...
2013 365 1440 0.2
So I have to calculate the ten minute mean values for each year and each day of the year. I created a code with with 3 loops in it. The first one for the year, the second one for the day and the third one for the minutes. It looks more or less like this: for y=2010:2013 idy=find(year==y) if ~isempty(idy) for d=1:366 idd=find(doy(idy)==d) if ~isempty(idd) for m=1:10:1440 idm=find(m(idd(idy))==m if ~isempty(idm) mean=[mean; y d m mean(value(idy(idd(idm))))]; end end end end end end
Now, where is the problem?!
It takes days to run and at the end matlab stucks so I have to exit and I can never get to the results...
Any sugestions would be really really APRECIATED!!!
Thank you in advance.
Cheers,
Melina
1 comentario
Melina Maria
el 1 de Jul. de 2014
Respuesta aceptada
Más respuestas (2)
amanita
el 1 de Jul. de 2014
0 votos
You can also use a parfor somewhere (if it is possible) but you will have to change your code a little bit.
3 comentarios
Melina Maria
el 1 de Jul. de 2014
amanita
el 1 de Jul. de 2014
You need independent jobs, so if you use parfor in your outer loop you will need to create N TENNILU's, where N is the total number of years (e.g you can create a cell for TENNILU, preallocate TENNILU{year} after the parfor year and set your counter to zero). If you use parfor you will also need to create a parallel pool (parpool)
Melina Maria
el 1 de Jul. de 2014
Andrei Bobrov
el 1 de Jul. de 2014
one way
d = [2010 132 150 1.52
2010 132 151 2.5
2010 132 153 3.4
2012 20 289 4.69
2013 365 1440 0.2];
sdate = addtodate(datenum(d(:,1),1,1),d(:,2) + d(:,3)/1440,'day');
b = datevec(sdate(1));
c = ceil(b(end)*.1)*10;
dte = datenum([[b(1:4),floor(b(5)*.1)*10,0];[c(1:4),ceil(c(5)*.1)*10,0]]);
z = addtodate(sdate(1),(0:10:ceil(diff(dte)*144)*10)','minute');
out = [datevec(z),accumarray(ii,d(:,end),size(z),@mean)];
1 comentario
Melina Maria
el 1 de Jul. de 2014
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!