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

8 visualizaciones (últimos 30 días)
Cl4udio
Cl4udio el 29 de Sept. de 2023
Editada: Cl4udio el 29 de Sept. de 2023
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 comentarios
Dyuman Joshi
Dyuman Joshi el 29 de Sept. de 2023
Why not just sort?
Do you want to find the longest non-continuous sub-array that is strictly increasing?
Cl4udio
Cl4udio el 29 de Sept. de 2023
Editada: Cl4udio el 29 de Sept. de 2023
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

Iniciar sesión para comentar.

Respuestas (3)

Torsten
Torsten el 29 de Sept. de 2023
Editada: Torsten el 29 de Sept. de 2023
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 el 29 de Sept. de 2023
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 el 29 de Sept. de 2023
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 comentarios
Mathieu NOE
Mathieu NOE el 29 de Sept. de 2023
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 el 29 de Sept. de 2023
Editada: Cl4udio el 29 de Sept. de 2023
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?

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by