Effacer les filtres
Effacer les filtres

i want to find maximum and minimum values in a matrix continuosly

1 vue (au cours des 30 derniers jours)
LISSA DUVVU
LISSA DUVVU le 28 Déc 2019
i want to find maximum and minimum values in a matrix
suppose i have data like
1
2
5
6
3
2
5
8
9
1
so my minimum is 1 and maximum is 6 and next minimum is 2 maximum is 9 again 1 like that
i want result as
1
6
2
9
1

Réponse acceptée

Chien-Han Su
Chien-Han Su le 28 Déc 2019
Try this
% define an arbitray array a
a = [1, 2, 5, 6, 3, 2, 5, 8, 9, 1];
if length(a) <= 2
extreme = a;
else
extreme = zeros(1,length(a));
extreme(1) = a(1); % first element must be extreme value
count = 1; % count the number of extreme value
if a(2) > a(1)
increase = true; % use 'increase' to record the trend of increasing or decreasing
else
increase = false;
end
for n = 3:length(a)
if a(n) > a(n - 1)
if increase == false
count = count + 1;
extreme(count) = a(n - 1);
end
increase = true;
else
if increase == true
count = count + 1;
extreme(count) = a(n - 1);
end
increase = false;
end
end
extreme(count + 1) = a(end); % last elements must be extreme value
extreme = extreme(1:count + 1);
end

Plus de réponses (0)

Catégories

En savoir plus sur NaNs dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by