Get the mean and standard deviation of the lower half of the first mode of a bimodal distribution

2 ビュー (過去 30 日間)
Hi, I have a bimodal distribution (in the form of a vector) from which I want to fit a gaussian distribution to the lower half of the first mode and calculate the mean and standard deviation of that distribution.
Any advice?

採用された回答

Image Analyst
Image Analyst 2020 年 9 月 4 日
Here is code that uses fitnlm() to fit two Gaussians, and one that fits multiple Gaussians.
  2 件のコメント
Stephen
Stephen 2020 年 9 月 4 日
My Q doesn't apply to this specific thread (pls accept my apologies), but I don't know how else to contact Image Analyst. Some time back you helped out a user with a Q re: opening/closing an excel file from within MatLab. I'm having a devil of at time with the PlotInExcel function by Amit Doshi and am hoping you might shed some light. The problem is: I can't figure out how to save the file and quit Excel at the end of PlotInExcel. Consequently, I can't get back to my script. Excel just hangs open and I have to save/close it manually. Do you have any ideas? Any help would be greatly appreciated!
function PlotInExcel
x= {1:10};
a= cell2mat(x);
y= {1:10};
b= cell2mat(y);
%............plotting..............................................................................................
plot(a,b);
xlabel('X Values');
ylabel('Y Values');
print -dmeta; %.................Copying to clipboard
FILE = 'C:\DATA.xlsx';
Range='OX14';
%.............excel COM object............................................................................
Excel = actxserver ('Excel.Application');
Excel.Visible = 1;
if ~exist(FILE,'file')
ExcelWorkbook=Excel.Workbooks.Add;
ExcelWorkbook.SaveAs(FILE);
ExcelWorkbook.Close(false);
end
invoke(Excel.Workbooks,'Open',FILE); %Open the file
ActiveSheet = Excel.ActiveSheet;
ActiveSheetRange = get(ActiveSheet,'Range',Range);
ActiveSheetRange.Select;
ActiveSheetRange.PasteSpecial; %.................Pasting the figure to the selected location
%-----------------------------------end of function"PlotInExcel--------------------------------------
Image Analyst
Image Analyst 2020 年 9 月 6 日
Stephen, add these lines:
Excel.ActiveWorkbook.Save;
Excel.Quit;
delete(Excel);
clear('Excel')
See attached utilities for Excel.

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

その他の回答 (1 件)

Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020 年 9 月 2 日
編集済み: Abdolkarim Mohammadi 2020 年 9 月 2 日
You can first determine the elements that are in the lower half
LowerHalfMask = Data <= mean(Data);
Then calculate the statistics
LowerHalfMean = mean(Data(LowerHalfMask));
LowerHalfStd = std(Data(LowerHalfMask));
To fit a distribution, you can first collect the elements of the lower half
LowerHalfValues = Data(LowerHalfMask);
Then use the Curve Fitting App (type cftool in the command window).
  1 件のコメント
Audun Kvalvaag
Audun Kvalvaag 2020 年 9 月 4 日
Thanks, I solved it by mirroring the lower half of the first mode with the flip function. I could then use this gaussian fit function: https://www.mathworks.com/matlabcentral/fileexchange/35122-gaussian-fit to get the mean and standard deviation.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by