필터 지우기
필터 지우기

how to plot histogram from an array ?

조회 수: 67 (최근 30일)
noble amin
noble amin 2021년 12월 22일
댓글: Image Analyst 2021년 12월 22일
Hi everyone, what the simplest code to plot a histogram from this table ?
( x-axis for frequencies ; y-axis for the numbers )

답변 (2개)

Image Analyst
Image Analyst 2021년 12월 22일
Try putting each of those into a vector. The x axis is actually Number, not frequency, and the bin heights (the counts) are actually the frequency. So you'd do
frequency = [3,9,13,21,9,4,1];
Number = linspace(11.945, 12.035, length(frequency));
bar(Number, frequency);
xlabel('Number');
ylabel('Frequency (count)')
grid on;
  댓글 수: 1
Image Analyst
Image Analyst 2021년 12월 22일
@noble amin I don't know how you're getting your original numbers but there is a variety of ways to read them in from a text file, like readmatrix(), importdata(), csvread(), etc. Once you have the numbers, if you want to put them into a table variable type you can use table() like this:
frequency = [3,9,13,21,9,4,1];
Number = linspace(11.945, 12.035, length(frequency));
t = table(Number(:), frequency(:), 'VariableNames', {'Number', 'frequency'})
t = 7×2 table
Number frequency ______ _________ 11.945 3 11.96 9 11.975 13 11.99 21 12.005 9 12.02 4 12.035 1
bar(t.Number, t.frequency);
xlabel('Number');
ylabel('Frequency (count)');
grid on;

댓글을 달려면 로그인하십시오.


the cyclist
the cyclist 2021년 12월 22일
Histograms start from the data before they have been binned. You just need a bar chart. If your data are stored in a MATLAB table named tbl, then
bar(tbl.Number,tbl.frequency)
You didn't really tell us how the data are stored, so you may need to manipulate the data first, to get it in the proper format.
  댓글 수: 2
noble amin
noble amin 2021년 12월 22일
how to create a matlab table named tbl ?
the cyclist
the cyclist 2021년 12월 22일
How is your data stored now? Can you upload a MAT file with the data? (Use the paperclip icon in the INSERT section of the toolbar.)
For your future reference, uploading an image of your data (as you did in your original question) is not very helpful.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by