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

2 Ansichten (letzte 30 Tage)
Andrew Sol
Andrew Sol am 21 Jan. 2023
Beantwortet: KSSV am 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.
  1 Kommentar
Andrew Sol
Andrew Sol am 21 Jan. 2023
Bearbeitet: Andrew Sol am 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);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 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

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by