plot gaussian and standard deviation on my histogram
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi everyone,
I have this code and have plotted the histogram and now want to have gaussian and standard deviation.
can anyone help me please?
figure('Name','A3{1}.BMd_Img_o_part1')
edges= linspace(0,255,21);
histogram(image1, 'BinEdges',edges,'normalization','pdf')
採用された回答
image1 = 42*randn(1,1000)+42*3; % Create Data
figure('Name','A3{1}.BMd_Img_o_part1')
edges= linspace(0,255,21);
[muHat,sgHat] = normfit(image1);
pdfplot = normpdf(edges, muHat, sgHat);
figure
histogram(image1, 'BinEdges',edges,'normalization','pdf')
hold on
plot(edges, pdfplot, '-r', 'LineWidth',2)
hold off
.
14 件のコメント
Thanks so much for your help. Just one question, does this code has standard deviation as well?
I am sorry, my plot looks like this how I can increase the hight of the gaussian peak to reach to my histogram figure?
Also, how can I add the standard deviation to my figure?
Thanks a lot
As always, my pleasure!
Increasing the height would not be appropriate. Note that the plot overestimates some of the bins, and underestimates some of the others.
I am not certain what you intend by ’Also, how can I add the standard deviation to my figure?‘ One possibility would be to use a text object. Otherwise, it depends on what you want to do and how you want the standard deviation depicted. The standard deviation is the second normfit output, ‘sgHat’.
Thanks a lot for your explanatin.
My image1 data is the 368x315x3 uint8.
I do not understand this line image1 = 42*randn(1,1000)+42*3.
Can you help me how I can consider my data?
As always, my pleasure!
‘My image1 data is the 368x315x3 uint8.’
I do not have your data to work with, or the code you used to create ‘image1’.
‘I do not understand this line image1 = 42*randn(1,1000)+42*3.’
I created data to use to test my code. I always do this if the actual data are not provided (as they were not provided here).
Note that the full line is:
image1 = 42*randn(1,1000)+42*3; % Create Data
.
This data was extracted from ultrasound Machine and as I have mentioned is 368x315x3 uint8 array.
Hope this information can help you and I would be gratfeul how I can plot the gaussian in this situation.
My code are listed as below;
imshow(Data_SWS_BMd_A3{1}.BMd_Img_o)
impixelinfo
xmin = 5;
xmax = 314;
ymin = 136;
ymax = 238;
imshow(Data_SWS_BMd_A3{1}.BMd_Img_o(ymin:ymax,xmin:xmax));
impixelinfo
image= Data_SWS_BMd_A3{1}.BMd_Img_o(ymin:ymax,xmin:xmax)
[n,m]=size(image)
id=fix(m/3)
image1=image(:,1:id);
image2=image(:,id+1:2*id);
image3=image(:,2*id+1:m);
figure
imshow(image1)
impixelinfo
figure
imshow(image2)
impixelinfo
figure
imshow(image3)
impixelinfo
figure('Name','A3{1}.BMd_Img_o_part1')
edges= linspace(0,255,21);
histogram(image1, 'BinEdges',edges,'normalization','pdf')
thanks a lot
Please let me know if you need any more information. I do really need to solve my problem as I need to report tomorrow in my meeting.
Thanks so much
It might be interesting to have the ‘image1’ vector you refer to here:
histogram(image1, 'BinEdges',edges,'normalization','pdf')
although havng it would not change anything I already wrote, so I doubt providing it would be worth the effort to attach it.
Unfortunately, image1 is not a vector, it is an array. When I am converting it to the vector as listed below it show this figure(i have attached here) which is not the figure that I am looking for
A = im2double(image1(:));
edges= linspace(0,255,21);
[muHat,sgHat] = normfit(A);
pdfplot = normpdf(edges, muHat, sgHat);
figure('Name','A3{1}.BMd_Img_o_part1')
histogram(image1, 'BinEdges',edges,'normalization','pdf')
hold on
plot(edges, pdfplot, '-r', 'LineWidth',2)
hold off
Note that the histogram function will take matrix arguments as well as vector arguments, although it will convert a matrix to a single-column vector for analysis.
I am lost as to what you are doing.
I am sorry, maybe I was not clear enough in explaining my question.
Let me explain from the beginning. I have plotted this histogram (see attachment please) and now want to have a gaussian plot which has overlab with the histogram.
Data already are in a grayscale.
imshow(Data_SWS_BMd_A3{1}.BMd_Img_o)
impixelinfo
xmin = 5;
xmax = 314;
ymin = 136;
ymax = 238;
imshow(Data_SWS_BMd_A3{1}.BMd_Img_o(ymin:ymax,xmin:xmax));
impixelinfo
image= Data_SWS_BMd_A3{1}.BMd_Img_o(ymin:ymax,xmin:xmax)
[n,m]=size(image)
id=fix(m/3)
image1=image(:,1:id);
image2=image(:,id+1:2*id);
image3=image(:,2*id+1:m);
figure
imshow(image1)
impixelinfo
figure
imshow(image2)
impixelinfo
figure
imshow(image3)
impixelinfo
edges= linspace(0,255,21);
[muHat,sigmaHat] = normfit(image1);
pdfplot = normpdf(edges, muHat, sigmaHat);
figure('Name','A3{1}.BMd_Img_o_part1')
histogram(image1, 'BinEdges',edges,'normalization','pdf')
hold on
plot(edges, pdfplot, '-r', 'LineWidth',2)
hold off
I am receiving error like this which I do not know what it is;
Error in normfit
xc = x - repmat(muhat,[n 1]);
And if I convert the image1 to the vector double it shows the graph which is not right.
I know it is becoming complicated and thanks so much for your patience. If still it is not clear I do appologize for that.
Kind regards
I do not understand what threw the error.
Please use the code I already wrote to plot the normal distribution on the histogram.
Thank you so much , I do really appreciate you efforts.
As always, my pleasure!
その他の回答 (1 件)
Fatemeh Shomal Zadeh
2020 年 9 月 8 日
this is a histogram figure that i have.
カテゴリ
ヘルプ センター および File Exchange で Histograms についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
