Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Replacing a for loop?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I've written a small script to calculate the short time energy function of a signal. However it feels a bit clunky and my data sets are quite large so processing takes a while. Is there a way to speed up this process using vectorisation? This is the code at the moment.
function EImat=EI_mod(A,seg_length)
rms=sqrt(((sum(A.^2))/length(A)));
for i=1:(length(A))/seg_length;
A1=A((i*seg_length)-(seg_length-1):(i*seg_length));
rms1=sqrt(((sum(A1.^2))/seg_length));
EImat(i)=rms1;
end
Any help will be greatly appreciated.
Thanks
Jack
Réponses (1)
Roger Stafford
le 14 Nov 2013
Modifié(e) : Roger Stafford
le 14 Nov 2013
EImat=sum(reshape(A,seg_length,[]).^2,1)/seg_length;
(Note: I assume here that the length of A is some integral multiple of seq_length.)
(Note 2: You don't return the 'rms' quantity in your function, so I haven't computed it here.)
0 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!