# Find the minimum and maximum value of internal intervals in an array

6 views (last 30 days)
Andrew Sol on 21 Jan 2023
Answered: KSSV on 21 Jan 2023
There is the following array:
It has several subintervals:
I'm trying to write code that extracts these sub-intervals and, most importantly, looks for the minimum and maximum value in these sub-intervals.
That is, the end result should look something like this:
I continue to work, but so far without success.
Andrew Sol on 21 Jan 2023
Edited: Andrew Sol on 21 Jan 2023
With the help of these two themes, I got the following code. Which seems to be working. Can it be simplified somehow?
array = array';
idx = all(isnan(array),2);
idr = diff(find([1;diff(idx);1]));
D = mat2cell(array,idr(:),size(array,2));
D{1:2:end}
Dmax=cellfun(@max,D);
Dmin=cellfun(@min,D);

KSSV on 21 Jan 2023
clc; clear all ;
array = [1 2 3 NaN NaN NaN -1 0 5 NaN 0.25 NaN 5 6 7];
M = array' ;
idx = isnan(M);
idr = diff(find([1;diff(idx);1]));
D = mat2cell(M,idr(:),size(M,2));
iwant = [] ;
for i = 1:length(D)
if ~any(isnan(D{i}))
iwant = [iwant minmax(D{i}')] ;
end
end
iwant
iwant = 1×8
1.0000 3.0000 -1.0000 5.0000 0.2500 0.2500 5.0000 7.0000

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by