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

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Andrew Sol
Andrew Sol il 21 Gen 2023
Modificato: Andrew Sol il 21 Gen 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);

Accedi per commentare.

Risposte (1)

KSSV
KSSV il 21 Gen 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

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by