필터 지우기
필터 지우기

histogram with two sets of data

조회 수: 4 (최근 30일)
Alexandre Williot
Alexandre Williot 2015년 5월 6일
댓글: Nicholas 2017년 2월 28일
Hello, I want to make an histogram exactly like the image here. Have you an idea ?

채택된 답변

Star Strider
Star Strider 2015년 5월 6일
Use the bar function with the 'grouped' option. The error bars and the comparison lines between the plotted bars are a bit more difficult, and the code the plot them depends on whether you are using R2014a or earlier, or R2014b or later.
  댓글 수: 4
Alexandre Williot
Alexandre Williot 2015년 5월 7일
Yes! It's perfect! Thank you very much.
Star Strider
Star Strider 2015년 5월 7일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Elvira Ruiz
Elvira Ruiz 2016년 10월 23일
I do not have enough words to express my gratitude. THANK YOU!
  댓글 수: 4
Star Strider
Star Strider 2016년 10월 25일
My pleasure.
That code was written for R2014a. HG2 graphics were introduced in R2014b.
Example code for R2014b (and later versions) for bar chart error bars is:
y = [212206000000 229040000000 39312320000; 119783500000 169247500000 128418300000 ; 211838000000 706581300000 85349300000];
hBar = bar(y);
set(gca,'XTickLabel', {'300 ','350 ','400 '})
legend('C','S','T', 'Location','N')
grid on
ylabel('N/m^{2}')
xlabel ('\mum')
colormap summer
for k1 = 1:size(hBar,2)
ctr(k1,:) = bsxfun(@plus, hBar(k1).XData, [hBar(k1).XOffset]'); % Centres Of Bar Groups
ydt(k1,:) = hBar(k1).YData; % Y-Data Of Bar Groups
end
hold on
for k1 = 1:size(hBar,2)
errorbar(ctr(k1,:), ydt(k1,:), ones(size(ydt(k1,:)))*0.1.*ydt(k1,:), '.r') % Plot 10% Error Bars
end
hold off
It’s been a while since I ran that, so I ran it just now on R2016b to check it. It works.
This also gives me the opportunity to include the R2014b code here. That should help other people who are looking for both versions.
Nicholas
Nicholas 2017년 2월 28일
Super helpful! Thank you for taking the time to post this answer!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by