Removing unwanted data from a Histogram

조회 수: 17 (최근 30일)
pratapaneni Chetan
pratapaneni Chetan 2021년 9월 23일
댓글: pratapaneni Chetan 2021년 9월 24일
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