Split the graph based on a specific value

5 ビュー (過去 30 日間)
jeon
jeon 2021 年 10 月 15 日
コメント済み: KSSV 2021 年 10 月 15 日
I have a graph like this.
This image is the part of the plot and the mean of y(77449x1 array) is 0.4943.
I want to divide it into small graphs by cut the graph from the part where y is the average of y.
Is it possible? If so, can I know what to do?
Or is it simpler to plot after dividing the y-value array than dividing the graph?

回答 (1 件)

KSSV
KSSV 2021 年 10 月 15 日
Let (x,y) be your data.
idx = knnsearch(y,mean(y)) ; % this will give index in y which is close to mean(y)
% plot
plot(x(1:idx),y(1:idx),'r')
hold on
plot(x(idx+1:end),y(idx+1:end),'b')
  2 件のコメント
jeon
jeon 2021 年 10 月 15 日
Thank you.
At first, I tried to use find but it didn't work.
But the result came out when I used knnsearch.
By the way, only one index value closest to mean(y) came out, so the graph could only be divided into two.
What I’m trying to do is to cut this graph where every mean(y).
I’ll try more.
KSSV
KSSV 2021 年 10 月 15 日
You can specify the number of points you want in knnsearch.
idx = knnsearch(y,mean(y),'k',10) ;
Also you can use simple inequalitilies to achieve the present.
tol = 10^-3 ;
idx = abs(y-mean(y))<=tol ;
idx = find(idx)
I would suggest to use the above.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by