Plot mean and standard deviations along with data on a bell curve
조회 수: 62 (최근 30일)
이전 댓글 표시
I have columns of data, numbering approximately 120 rows. The data is 1 thru 5, representing survey data. I am working on analyzing the data columns. The column data also has some NaN. I can calculate the mean and standard deviations. However, I am attempting to plot the mean, standard deviations, along with the actual data on the bell curve. I found this code that at least plots the data. But I am not sure how to change the code to correctly represent my data on a bell curve. For instance, I don't think I need the randn function, given the amount of data I have. In short, I just want to plot my data, the mean, and standard deviations (to plus and minus 3 sigma) for all columns of data on the bell curve, similar to what this code produces.
x = .03*randn(10000,1)+.34;
[N,X] = hist(x,100);
hfig = figure;
bar(X,N)
hold on;
y = [0 1.2*max(N)];
center = mean(x);
std1 = std(x);
%center plot
plot([center center],y,'r-.')
%1 std
plot([center center]+std1,y,'g-.')
plot([center center]-std1,y,'g-.')
%2 std
plot([center center]+2*std1,y,'k-.')
plot([center center]-2*std1,y,'k-.')
댓글 수: 10
Image Analyst
2020년 6월 19일
You can use the isnan() function along with sum() to compute the number of nans in a vector.
numNans = sum(isnan(yourVector));
percentNans = 100 * numNans / numel(yourVector);
답변 (1개)
Image Analyst
2020년 5월 22일
Then if it's not normally distributed data, why do you want to fit a bell curve to it?
Did you try fitdist():
load hospital
x = hospital.Weight;
pd = fitdist(x,'Normal')
x_values = 50:1:250;
y = pdf(pd,x_values);
plot(x_values,y,'LineWidth',2)
댓글 수: 1
Image Analyst
2020년 5월 22일
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!