Code optimization for loop
Afficher commentaires plus anciens
Dear experts could you help me to optimize the code please? My files represent a long series of data points in many columns and it takes ages to calculate the parameters I need by the for loop. My computer is not so powerful too. I tried parfor, it did not help much. Thank you. Oleg
filename= 'data.xlsx';
signal=xlsread(filename,'b:t');
Time=xlsread(filename,'a:a');
detrend_data = detrend(signal, 'linear');
nSig = size(detrend_data);
N = 0;
NPEAKS = zeros([nSig,1]);
NINT = zeros([nSig,1]);
for jj = 1:nSig(2)
[pks, locs, width, p] = findpeaks(detrend_data(:,jj),Time,'MinPeakProminence',0.1,'MinPeakHeight',0.2,'MinPeakDistance',0.5,'Annotate','extents','WidthReference','halfprom');
peakInterval = diff(locs);
lp = length(p);
li = length(peakInterval);
N = max(N,lp);
Ni=max(N,li);
NPEAKS(1:lp,jj) = cat(2,pks);
NLOCS(1:lp,jj) = cat(2,locs);
NWIDTH(1:lp,jj) = cat(2,width);
NPROM(1:lp,jj) = cat(2,p);
NINT(1:li,jj) = cat(3,peakInterval);
end
NPEAKS = NPEAKS(1:N,:);
NLOCS = NLOCS(1:N,:);
NWIDTH = NWIDTH(1:N,:);
NPROM =NPROM(1:N,:);
NINT=NINT(1:Ni,:);
sheet=1;
sheet2=2;
sheet3=3;
sheet4=4;
sheet5=5;
filename2= 'peaks_data';
xlswrite(filename2,NPEAKS,sheet);
xlswrite(filename2,NLOCS,sheet2);
xlswrite(filename2,NWIDTH,sheet3);
xlswrite(filename2,NPROM,sheet4);
xlswrite(filename2,NINT,sheet5);
2 commentaires
Rik
le 8 Août 2018
Without the data itself we can't do very much.
Oleg Tolstenkov
le 8 Août 2018
Réponses (0)
Catégories
En savoir plus sur Multiobjective Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!