How to only plot data points within a certain range?

8 ビュー (過去 30 日間)
Brian Hsiao
Brian Hsiao 2018 年 5 月 4 日
コメント済み: Star Strider 2018 年 5 月 4 日
Let's say I have data points from 1 to 10000 (logarithmic) for both x and y, but only want to plot the points for x>10 and y<10 on a scatter plot. How would I do that?
What if I were to only exclude that region from the graph? How would I go about doing that?
Moreover, how can I count the number of data points only within that region using MatLab?

回答 (1 件)

Star Strider
Star Strider 2018 年 5 月 4 日
One approach:
x = randi(50, 1, 50); % Create Data
y = randi(50, 1, 50); % Create Data
figure(1)
scatter(x, y, 'p')
grid
axis([0 50 0 50])
title('Original Data')
m = (x > 10) & (y < 10); % Select Data (Logical Vector)
figure(2)
scatter(x(m), y(m), 'p')
grid
axis([0 50 0 50])
title('Selected Data')
  2 件のコメント
Brian Hsiao
Brian Hsiao 2018 年 5 月 4 日
Thank you! How do I count the number of points within that range?
Star Strider
Star Strider 2018 年 5 月 4 日
My pleasure!
One additional line will give you that information:
m = (x > 10) & (y < 10); % Select Data (Logical Vector)
NrInRange = nnz(m); % Number Of Points Meeting Criteria
another option:
NrInRange = sum(m); % Number Of Points Meeting Criteria

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

カテゴリ

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