フィルターのクリア

Histogram: put mean and std in the legend

10 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2018 年 4 月 4 日
回答済み: Gareth 2018 年 11 月 20 日
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)

回答 (1 件)

Gareth
Gareth 2018 年 11 月 20 日
I am using R2018b and my understanding is that you want to have:
  • each line on your plot not named data, but the legend itself has the value of the mean/std of the line
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);

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by