first time use Histogram, need help

3 ビュー (過去 30 日間)
Xiao yang
Xiao yang 2024 年 9 月 5 日
編集済み: Adam Danz 2024 年 9 月 6 日
need help
  2 件のコメント
the cyclist
the cyclist 2024 年 9 月 5 日
You say you need help, but you don't really say what help you need.
  • Describe what you are trying to do, in more detail.
  • Share any code you have written yourself.
  • What input data do you have? Can you share the data here (by uploading a MAT file with the data)?
Xiao yang
Xiao yang 2024 年 9 月 5 日
input data from Density - Frequency table, which I photo from my text book, need help how for to plot Histograh.

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

回答 (2 件)

Adam Danz
Adam Danz 2024 年 9 月 6 日
編集済み: Adam Danz 2024 年 9 月 6 日
In MATLAB, I recommend using the histogram function.
x = reshape([0.29:0.01:0.4], 2, []);
xlabels = compose('%.2f-%.2f', x.');
y = [30 75 32 9 3 1];
figure
histogram('Categories',categorical(xlabels), 'BinCounts', y, 'FaceColor', 'red')
ylabel('Frequency')
xlabel('Density')
Note that the x-values are not continuous. For example, there are no data between x=0.30 and x=0.31. This is why the ranges are plotted as categories.

Star Strider
Star Strider 2024 年 9 月 5 日
編集済み: Star Strider 2024 年 9 月 5 日
The histogram has already been created.
Use the bar function to plot it —
x = reshape([0.29:0.01:0.4], 2, []);
y = [30 75 32 9 3 1];
figure
hb = bar(mean(x), y, 'hist');
hb.FaceColor = 'r';
Ax = gca;
Ax.XTick = mean(x);
Ax.XTickLabel = compose('%.2f-%.2f', x.');
pos = Ax.Position;
xl = xlim;
yl = ylim;
xapf = @(x,pos,xl) pos(3)*(x-min(xl))/diff(xl)+pos(1); % 'x' Annotation Position Function
yapf = @(y,pos,yl) pos(4)*(y-min(yl))/diff(yl)+pos(2); % 'y' Annotation Position Function
annotation('textarrow',xapf([0.395 0.395],pos,xlim), yapf([40 5],pos,ylim), 'String',["Less than 1%" "of samples near the" "undesirable 0.40 level"])
xlabel('Denisty')
ylabel('Frequency')
title('Histogram of Density Data')
EDIT — Added annotation object.
.
  5 件のコメント
Star Strider
Star Strider 2024 年 9 月 5 日
@Xiao yang — My pleasure. You have to have the original data to use any histogram function.
I have no experience with R, and I never heard of JMP.
@Walter Roberson — Thank you!
Image Analyst
Image Analyst 2024 年 9 月 6 日
"teacher want students use R or JMP to plot this Histogram" <== then do so. It's what your teacher wants -- to use R or JMP rather than MATLAB. Your teacher did not say "Ask others to solve the problem for you so you can turn their code in."
This looks like a homework problem. If you have any questions ask your instructor or read the link below to get started:
Obviously, if it is homework, we can't give you the full solution because you're not allowed to turn in our code as your own. No offense -- we just don't want you to get into trouble with your teacher.

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

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by