Execute code faster for saving files with a matrix
显示 更早的评论
Hey guys! How are you. I need my code to execute faster. Here's the deal.
I have a matrix which is: datos2009(141214 x 11). I need to save files extracting information from that matrix, in the first column I have to save the data from 8, then the 10 and so on.
datos2009=[
8 29.24 5.96 10.6 0.06 0.69 22 72 -95.16 18.11 42.1
8 29.32 5.93 10.6 0.08 0.9 8 14 -95.16 18.11 42.1
8 30.19 6 10.6 0.06 0.69 14 28 -95.16 18.11 42.03
10 51.76 6.06 10.3 0.05 0.59 27 83 -95.16 18.11 41.42
10 51.84 5.66 10.3 0.05 0.59 14 40 -95.16 18.11 41.42
11 55.33 5.6 10.3 0.05 0.59 19 40 -95.16 18.11 41.37
11 55.68 5.9 10.3 0.07 0.8 15 39 -95.16 18.11 41.37]
prompt = 'Indique la ruta para guardar los archivos';
fpath=input(prompt,'s');
j=0;
k=datos2009(1);
header={'Costura', 'Kilometraje', 'Posición horaria', 'Espesor', 'Porcentaje de profundidad', 'Profundidad', 'Largo','Ancho', 'Longitud GPS', 'Latitud GPS', 'Elevación'};
cont=1;
values2009=zeros(50,11);
for i=1:size(datos2009)
j=datos2009(i);
if j==k
values2009(cont,:)=datos2009(i,:);
cont=cont+1;
else
zeroRow=~all(values2009, 2);
values2009(zeroRow,:)=[];
d = [header;num2cell(values2009)];
fileName=sprintf(strcat('File','%04d','_T_%d.csv'),k,k);
fullFileName=fullfile(fpath,fileName);
xlswrite(fullFileName,d);
values2009=zeros(50,11);
cont=1;
values2009(cont,:)=datos2009(i,:);
cont=cont+1;
k=j;
end
end
Any ideas how to run faster my code, taking into consideration that it takes around 12 hours to finish the job, about 5000 files are saved.
Thanks in advance.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Image Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!