필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
LISSA DUVVU
LISSA DUVVU 2019년 12월 28일
답변: Chien-Han Su 2019년 12월 28일
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

채택된 답변

Chien-Han Su
Chien-Han Su 2019년 12월 28일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by