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.
2 件のコメント
"Any ideas how to run faster my code"
Don't use xlswrite to write text files!
Do not convert between data classes (e.g. split numeric matrix into cell array).
If speed is your main concern, then write to file using low-level commands, e.g. fprintf.
Adrian Verdin
2019 年 7 月 9 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!