how speed up or avoid loops
Ältere Kommentare anzeigen
I think there must be ways to avoid for loops, but have not found the correct magic matlab syntax for doing so. Can someone suggest how I might make the following more efficient? -Jeff
% example.m
% how can I speed up inner loop(s) here?
% create random array of signals (Nchannel x Nframes)
% for each pair of signals compute difference wave
% for each wave, integrate over moving window Nwin wide
% will be flat epochs at beginning and end of integrated difference waves,
% Hwin wide
nchan = 4;
nprs = nchan*(nchan-1)/2;
nfrm = 1000;
data = rand(nchan,nfrm)-0.5;
new = zeros(nprs,nfrm);
hwin = 10;
nwin = 2 * hwin + 1;
fnwin = single(nwin);
ipr = 0;
for ich = 1:nchan-1
for jch = ich+1:nchan
ipr = ipr + 1;
dif = data(jch,:) - data(ich,:);
rsum = 0;
for ifr = hwin+1:nfrm-hwin
sum = 0;
for jfr = ifr-hwin:ifr+hwin
sum = sum + dif(jfr);
end
new(ipr,ifr) = abs(sum/fnwin);
end
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Periodic Waveform Generation finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!