Create an array with only the increasing values of a pressure time series.
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
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?
Respuestas (3)
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)
0 comentarios
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
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')
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!