how to find the max and min numbers by comparing each and every adjacent element in an array?

1 view (last 30 days)
i have an array say A=[-2, 4, -5, 6] now i want to find the max and min value bewteen each adjacent numbers. for example, A=[-2,4,-5,6] answer should be between [-2,4] 4 is max and -2 is min and again between [4,-5] 4 is max and -5 is min

Answers (1)

Walter Roberson
Walter Roberson on 19 Oct 2015
At = [A(1:end-1); A(2:end)];
Amin = min(At);
Amax = max(At);

Products

Community Treasure Hunt

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

Start Hunting!