Removing unwanted data from a Histogram

20 views (last 30 days)
In the given histogram below, I want to remove all the data thats below 4000 on the Y axis. How can this be done?
Thanks in advance :)

Accepted Answer

Image Analyst
Image Analyst on 24 Sep 2021
Here is a full demo. Attach your data or histogram if you need more help.
% Demo by Image Analyst.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
% str = "MathWorks was founded in 198.4. Patterns were 1st introduced in R2020b.";
% pat = digitsPattern;
% % pat = lettersPattern;
% year = extract(str,pat)
data = 10 + 5 * randn(1000000, 1);
subplot(2, 1, 1)
counts = histcounts(data); % Get histogram.
bar(counts, 1);
grid on;
title('Original -- All Bins', 'FontSize', fontSize);
xlabel('Value', 'FontSize', fontSize);
ylabel('Counts', 'FontSize', fontSize);
yline(4000, 'Color', 'r', 'LineWidth', 2);
indexes = counts < 4000; % Find out what bins have less than 4000 counts.
counts(indexes) = 0; % Set those bins to zero.
subplot(2, 1, 2)
bar(counts, 1);
grid on;
title('Now With Bins Below 4000 Zeroed Out', 'FontSize', fontSize);
xlabel('Value', 'FontSize', fontSize);
ylabel('Counts', 'FontSize', fontSize);
yline(4000, 'Color', 'r', 'LineWidth', 2);
fprintf('Done running %s.m\n', mfilename);

More Answers (0)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!