Help with Plotting the Envelope of a Scatter Plot in MATLAB

23 ビュー (過去 30 日間)
Zac Lee
Zac Lee 2025 年 8 月 4 日
コメント済み: Zac Lee 2025 年 8 月 5 日
Hello everyone,
I'm trying to plot the envelope of a scatter plot in MATLAB. However, when I use the envelope function, it returns the same plot without highlighting the upper or lower bounds.
This plot was created using a scatter plot, and when I attempt to filter it to retain only the extremum values, I end up with just a single slice of the data.
Has anyone encountered a similar issue or knows how I could extract and plot the envelope correctly (in red), as shown in the reference image?
Thanks in advance!
  2 件のコメント
Zac Lee
Zac Lee 2025 年 8 月 4 日
移動済み: Star Strider 2025 年 8 月 4 日
Dear @Star Strider, here my x,y datas. The code is simply the classical roots of a 2nd degree polinomial equation.
Catalytic
Catalytic 2025 年 8 月 4 日
編集済み: Catalytic 2025 年 8 月 4 日
The sampling density is very non-uniform, and makes it hard to see why the red boundary is appropriate in certain places. Why couldn't someone assume the following boundary drawing be valid? You need to achieve denser sampling throughout the shape for any automatic boundary detector to have any hope.

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

採用された回答

Matt J
Matt J 2025 年 8 月 4 日
load xy
x=x(:); y=y(:);
[G,yg]=findgroups(y);
xmin=splitapply(@min,x,G);
xmax=splitapply(@max,x,G);
[yg,is]=sort(yg);
xmin=xmin(is);
xmax=xmax(flip(is));
X=[xmin;xmax]; Y=[yg;flip(yg)];
scatter(x,y,'.');hold on
plot(X,Y,'r-x'); hold off
  1 件のコメント
Zac Lee
Zac Lee 2025 年 8 月 4 日
Dear @Matt J, thank you verymuch for your help. it seems working

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

その他の回答 (2 件)

Star Strider
Star Strider 2025 年 8 月 4 日
編集済み: Star Strider 2025 年 8 月 4 日
The boundary function or related functions can probably help with this.
Since the data appear to have stepwise y-values, another option would be to get the x-values at each y-value. This could be a problem between y-values 0.02 to 0.027 since those x-values are discontinuous. Depending on how your data are presented, that could be either straightforward or somewhat difficult.
Without your data and the code you used to create that plot, I cannot experiment with either of these approaches.
EDIT -- Corrected typographical errors.
.

Catalytic
Catalytic 2025 年 8 月 4 日
編集済み: Catalytic 2025 年 8 月 4 日
load xy
x=x(:)/1000; y=y(:);
r=median(diff(unique(y)));
shp=alphaShape([x,y],r*.8);
[~,P]=boundaryFacets(shp);
scatter(x,y,'.b'); hold on
plot(P(:,1),P(:,2),'r.--'); hold off
  4 件のコメント
Catalytic
Catalytic 2025 年 8 月 4 日
If you increase the sampling density in the region y<0.005, as I mentioned in my comment above, then there would be not need to incorporate a second method.
load xy
x=x(:); y=y(:);
r=median(diff(unique(y)));
s=1000;
shp=alphaShape([x/s,y],r*.8);
[~,P]=boundaryFacets(shp);
P(:,1)=P(:,1)*s;
scatter(x,y,'.b'); hold on
plot(P(:,1),P(:,2),'r.--'); hold off
Zac Lee
Zac Lee 2025 年 8 月 5 日
Perfect! Tnak you verymuch for your help

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

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by