フィルターのクリア

Why does histogram gives issues? I rephrased my question

2 ビュー (過去 30 日間)
Sadiq Akbar
Sadiq Akbar 2022 年 11 月 16 日
コメント済み: Sadiq Akbar 2022 年 11 月 20 日
I have the following set of data:
fitness1=rand(100,1)*1e-7;
fitness2=rand(100,1)*1e-5;
fitness3=rand(100,1)*1e-3;
Each set of fitness1, fitness2 and fitness3 has 100 independent elements. I want to plot its histogram such that the x-axis is logrithmic having values like 10^-2, 10^-3, 10^-4....and the y-axis shows us how many elements have that corresponding fitness values in each fitness? Say for example we have 10^-3 on axis, so how many values in each fitness1, fitness2 and fitness3 are there having values in the range of 10^-3. Likewise, if we have 10^-5 on x-axis, then how many values in side each fitness are there having this range of 10^-5 and so on. I tried the following but its not like the one in the attachment.
clear all
clc
load 2sn35
one=sort(one,'descend');
fitness2sn35=one;
load 2sn45
one=sort(one,'descend');
fitness2sn45=one;
[~,edges1] = histcounts(log10(fitness2sn35));%[~,edges] = histcounts(log10(x));
[~,edges2] = histcounts(log10(fitness2sn45));
histogram([log10(fitness2sn35) log10(fitness2sn45)] )% histogram(log10(fitness2sn35))
xticklabels(num2cell(10.^get(gca,'XTick')));
I want a grpah like this, but I don't get like this?

回答 (2 件)

Steven Lord
Steven Lord 2022 年 11 月 16 日
x = rand(1, 1e5)*1e-5;
ax = axes;
Specify bins edges with logarithmic spacing.
h = histogram(ax, x, 10.^(-10:-5));
Set the XScale property of the axes to 'log'. You need to do this after the call to histogram not before.
ax.XScale = 'log';
  8 件のコメント
Sadiq Akbar
Sadiq Akbar 2022 年 11 月 17 日
Ok dear Walter Roberson.
Sadiq Akbar
Sadiq Akbar 2022 年 11 月 17 日
I wrote the code according to Steven as follows:
clear all
clc
load 2sn35 %x = rand(1, 1e5)*1e-5;
x1=sort(one,'descend');
fitness2sn35=x1;
load 2sn45 %x = rand(1, 1e5)*1e-5;
x2=sort(one,'descend');
fitness2sn35=x2;
ax = axes;
%Specify bins edges with logarithmic spacing.
h = histogram(ax, x1, 10.^(-10:-5));
h = histogram(ax, x2, 10.^(-10:-5));
%Set the XScale property of the axes to 'log'. You need to do this after the call to histogram not before.
ax.XScale = 'log';
But it gives me an empty figure widow.

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


Image Analyst
Image Analyst 2022 年 11 月 17 日
See my collection of demos attached that put insets within larger axes.
  12 件のコメント
Walter Roberson
Walter Roberson 2022 年 11 月 20 日
If you have data that is not yet had the bins analyzed, then use histogram()
If you have counts for each bin then call bar(BINLOCATIONS, COUNTS)
Sadiq Akbar
Sadiq Akbar 2022 年 11 月 20 日
Thank you very much dear Walter Roberson for your kind response. Each variable "one" has 100 different values. So if we show the x-axis as logrithmic and the y-axis will show count values from 1 to 100. Actually someone said to me use "histcounts" and "histogram" and then he gave me the above code, but I don't understand it and also it doesn't give me the graph like the one in the attachment. I don't understand what does histcounts does and what does histogram does? And why do we write [~,edges1] as output arguments in hiscounts but doesn't write some output arguments in histogram. Further, x-axis is also not logrithmic like 10^-1, 10^-2, 10^-3,.....10^-10 etc.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by