필터 지우기
필터 지우기

Create an array with only the increasing values of a pressure time series.

조회 수: 6 (최근 30일)
Cl4udio
Cl4udio 2023년 9월 29일
편집: Cl4udio 2023년 9월 29일
Hi, I'm trying to find a more "elegant" way to create an array using only the increasing values of a time series, so the generated time series will have a positive and increasing slope.
I will appreciate any help, best regards.
clear all,close all;
load DATA;
for i = 1:20; % just a big random number for the if cycle.
if find(diff(a) < 0);
id1 = diff(a);
id1 = find(id1>0);
a = a(id1);,clear id1;
else
disp('No more decreasing values')
end
end
  댓글 수: 4
Dyuman Joshi
Dyuman Joshi 2023년 9월 29일
Why not just sort?
Do you want to find the longest non-continuous sub-array that is strictly increasing?
Cl4udio
Cl4udio 2023년 9월 29일
편집: Cl4udio 2023년 9월 29일
Hi, so imagine that you are on a bout/vessel, and you measure the presurre with a sensor that you attach to a line and , you throw that sensor into the ocean, the bout is moving up and down (ocan waves). So you dont want those re-sampled measures of the ocean during time when the pressure is not increasing, when the instrument is going up and not down. So the sensor is also measuring other variables, so im using the increasing pressure data to uderstand the vertical high frecuency of the ocean....sorry if is confussing.
YES, THOSE ARE THE PERFECT WORDS Longest non-continuous sub-array that is strictly increasing, Thanks

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

답변 (3개)

Torsten
Torsten 2023년 9월 29일
편집: Torsten 2023년 9월 29일
I prefer a clean for-loop:
a_monotone(1) = a(1);
for i = 2:numel(a)
if a(i) > a_monotone(end)
a_monotone(end+1) = a(i);
else
a_monotone(end+1) = a_monotone(end);
end
end
hold on
plot(a_monotone)
plot(a)
hold off

Voss
Voss 2023년 9월 29일
This?
load DATA
plot(a)
idx = diff(a) <= 0;
while any(idx)
a([false; idx]) = [];
idx = diff(a) <= 0;
end
plot(a)

Mathieu NOE
Mathieu NOE 2023년 9월 29일
maybe this ?
I don't see the benefit of removing the negative slope segments , this creates gaps in the signal
was just smoothing or a first order polynomial fit not the best options ?
load DATA;
x = 1:numel(a);
ind_all = [];
val_all = [];
for k = 2:numel(a)
d = a(k) - a(k-1);
if d>0 % keep both y(k) - y(k-1)
ind = [k-1; k];
val = [a(k-1); a(k)];
% store all occurences
ind_all = [ind_all; ind];
val_all = [val_all; val];
end
end
% remove duplicates (use ind_all to do this task)
[C,IA,IC] = unique(ind_all);
val_unique_pos = val_all(IA);
plot(x,a,'-*b',C,val_unique_pos,'*d')
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2023년 9월 29일
if you are not too strict about some points at the edges , you can use a one line code with gradient
differences are minor with previous code
% comparison with gradient
id = find(gradient(a)>0);
plot(x,a,'-*b',C,val_unique_pos,'*r',id,a(id),'*g')
Cl4udio
Cl4udio 2023년 9월 29일
편집: Cl4udio 2023년 9월 29일
gradient! Look like is the way, dont understand why those green points in the red circlure, those are lower values that the indicaated with the arrows.. Thanks Mathieu! *Gaps are great, all those values that r not in increasing order are removed from the time serie.
notice that
diff(a(gradient(a)>0))
found decreasing values.
, right?

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

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by