How to store some varialbes from a very large loop?
Mostrar comentarios más antiguos
Hello,
I am sorry if this is a dumb question, I am not a very experienced programmer. All help is greatly appreciated.
I am trying to find the local maxima of a complex system. I have an array pattern (theta, dB) with multiple peaks. I have used findpeaks in the past to do this, however my values are now complex numbers and findpeaks does not support this. I am currently using a simple code to find this, which is shown below, but the way I am storing my values returns a matrix the size of the loop, with the values I want from the if statement, and the rest of the values are zero.
for n = 1:size(ArrayPattern_dB)-1
if ArrayPattern_dB(n)> ArrayPattern_dB(n+1) && ArrayPattern_dB(n)>ArrayPattern_dB(n-1);
disp(ArrayPattern_dB(n))
disp(theta_deg(n))
A(n) = ArrayPattern_dB(n);
B(n) = theta_deg(n);
Peaks = [B A];
end
end
I would like to just return a matrix that contains the value and location of the peaks, but I cannot think of a way to do this.
Thank you, Jason
1 comentario
Youssef Khmou
el 21 de Abr. de 2014
First proposition : use the absolute value of the pattern (abs(.)) then apply the algorithm for peak detection,
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!