Create an array with only the increasing values of a pressure time series.
조회 수: 6 (최근 30일)
이전 댓글 표시
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
2023년 9월 29일
Why not just sort?
Do you want to find the longest non-continuous sub-array that is strictly increasing?
답변 (3개)
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)
댓글 수: 0
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
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')
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!