Removing unwanted data from a Histogram

17 次查看(过去 30 天)
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 :)

采纳的回答

Image Analyst
Image Analyst 2021-9-24
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by