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

2 visualizaciones (últimos 30 días)
Andrew Sol
Andrew Sol el 21 de En. de 2023
Respondida: KSSV el 21 de En. de 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 comentario
Andrew Sol
Andrew Sol el 21 de En. de 2023
Editada: Andrew Sol el 21 de En. de 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);

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 21 de En. de 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

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by