- each line on your plot not named data, but the legend itself has the value of the mean/std of the line
Histogram: put mean and std in the legend
조회 수: 17 (최근 30일)
이전 댓글 표시
In the code below I will have histograms of three series. I want to have mean and std of three series calculated and displayed in the legend of each series. Please advise.
w=0:0.05:1;
ncount1 = histc(x(:,1),w);
relativefreq1=ncount1/NSamples;
ncount2 = histc(x(:,2),w);
relativefreq2=ncount2/NSamples;
ncount3 = histc(x(:,3),w);
relativefreq3=ncount3/NSamples;
figure (4)
plot(w, relativefreq1)
hold on
plot(w, relativefreq2,'LineWidth',1.0)
hold on
plot(w, relativefreq3,'LineWidth',1.5)
legend('Data1','Data2','Data')
title('Distribution of Data')
xlabel('Data')
ylabel('Frequency')
xlim([min(w) max(w)])
set(gca, 'xtick', w)
댓글 수: 0
답변 (1개)
GT
2018년 11월 20일
I am using R2018b and my understanding is that you want to have:
If this is the case maybe this example might help you:
data = rand(10,3); %as the data here is not relevant to your question
plot(data);
mymean = mean(data);
mystd = std(data);
% Create Legend
mylegend = "std: " + string(mystd) + " mean: " + string(mymean);
%add to plot
legend(mylegend);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!