running blocks of code in parallel?

Bill Denney bill at denney.ws
Tue Dec 9 19:58:33 CST 2008


Jared wrote:
> I have the following code that I need to run on several matrices. Is 
> there a way to run the code in some kind of parallel fashion so that I 
> don't need to wait for one block to finish before the other starts?
> for i=1:length(DJI)
> DJI2(i,1)=datenum(char(DJI(i,2)),'yyyy-mm-dd');
> DJI2(:,2:6) = reshape(str2num(strvcat(DJI(:,3:7)(:)), length(DJI(:,3:7))));
> end
Hi Jared,

FYI, when I sent the suggestion earlier, I meant

for i=1:length(DJI)
  DJI2(i,1)=datenum(char(DJI(i,2)),'yyyy-mm-dd');
end
DJI2(:,2:6) = reshape(str2num(strvcat(DJI(:,3:7)(:)), length(DJI(:,3:7))));

And now that I've had a chance to take a couple minutes off of my day
job, the better way to do this would be:

tmp = strvcat(DIJ(:,2));
y = str2num(tmp(:,1:4));
m = str2num(tmp(:,6:7));
d = str2num(tmp(:,9:10))
DJI2(i,1)=datenum(y, m, d);
DJI2(:,2:6) = reshape(str2num(strvcat(DJI(:,3:7)(:)), length(DJI(:,3:7))));

That should be much faster than the loop and than having datenum do the
string processing.

Have a good day,

Bill


More information about the Help-octave mailing list