How to take the maximum value of an array?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
arina octave
le 25 Fév 2015
Commenté : Star Strider
le 25 Fév 2015
Hi, I have this array a = [1:20]. How do I take the maximum value of every 5 elements of it. So I will have b = [5 10 15 20]. Anyone can help me? Thank you.
0 commentaires
Réponse acceptée
Plus de réponses (1)
Greig
le 25 Fév 2015
Try something like this...
a=1:20;
steps = 5;
b = NaN(mod(length(a)/steps,steps), 1); % preallocate b for speed, if you want to run larger loops
count = 1; % an index count for b in the loop
for ii = 1:steps:length(a)-(steps-1)
inds = ii:ii+(steps-1); % The indices we are interested in
b(count) = max(a(inds)); % Get the max
count = count+1; % add 1 to the counter
end
Voir également
Catégories
En savoir plus sur Matched Filter and Ambiguity Function dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!