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

조회 수: 2 (최근 30일)
Andrew Sol
Andrew Sol 2023년 1월 21일
답변: KSSV 2023년 1월 21일
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
Andrew Sol
Andrew Sol 2023년 1월 21일
편집: Andrew Sol 2023년 1월 21일
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);

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2023년 1월 21일
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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by