Separating of succecive monotonic vectors
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
moncef soualhi
le 9 Sep 2019
Commenté : moncef soualhi
le 10 Sep 2019
Hi every one,
I have a vector which contains values. These values consist of several monotonic vectors (as show in the figure). For this purpuse, i'd like to extract each monotone vector alone. Is there a solution to be able to isolate each monotone vector from the global one?
Thank you for your attention and tyour help
2 commentaires
the cyclist
le 9 Sep 2019
Could you also upload the original data from which you made that plot, in a MAT file?
Réponse acceptée
Fabio Freschi
le 9 Sep 2019
Let's assume your data are stored in x and y vectors. I take them from your picture
% get the data from picture
fig = gcf;
axObjs = fig.Children
dataObjs = axObjs.Children
x = dataObjs(1).XData;
y = dataObjs(1).YData;
your data are noisy. Let's specify a suitable threshold
threshold = 200;
the "negative jumps can be identified using diff
idx = [0 find(diff(y) < -threshold) length(y)];
the chunks of monotonical data have different sizes, I load them into a cell array
X = arrayfun(@(i)x(idx(i)+1:idx(i+1)),1:length(idx)-1,'UniformOutput',false);
Y = arrayfun(@(i)y(idx(i)+1:idx(i+1)),1:length(idx)-1,'UniformOutput',false);
Graphical check
figure, hold on
for i = 1:length(Y)
plot(X{i},Y{i})
end
3 commentaires
Fabio Freschi
le 9 Sep 2019
diff(y) < -threshold is a logical vector idx that contains the indices in the data vector where the jump is larger than the thrashold. With find we get the indices values. I added a leading 0 and a trailing 7538 (vector length) for the successive processing.
arrayfun is a nice matlab function. Have a look at the documentation for details. In this case that mimics in one row the following for loop
for i = 1:length(idx)-1
Y{i} = y(idx(i)+1:idx(i+1));
end
It loads in the ith cell of Y the monotonic portion of the vector y with starting index idx(i)+1 and final index idx(i+1)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!