i'm trying to plot a Histrogram with a data I got from working
%----------------------------------------------------------------
%
%--------------------------------------------------------------
filename = 'Mass_change_forMatlabNew.xlsx';
readdata = xlsread(filename);
X1 = (15) ;
X2 = (30) ;
X3 = (45) ;
Y1 = readdata(:,2) ;
Y2 = readdata(:,4) ;
Y3 = readdata(:,6) ;
%-------------------------------------------------------------------
%
%-----------------------------------------------------------------
Hist(X1,Y1)
Hist(X2,Y2)
Hist(X3,Y3)
data I have from lab
800 Celcius 700 Celcius 600Celcius
15percentage Carbon 0.000709 0.00015 0.000161
30percentage Carbon 0.000375 0.000261 0.00042
45percentage Carbon 0.002765 0.000344 0.000724
data I'm putting in excel (imagine it has a box)
filename Mass_change_forMatlabNew
15 0.000709 30 0.00375 45 0.002765
15 0.00015 30 0.000261 45 0.000344
15 0.000161 30 0.00042 45 0.000724
a picture above is a graph that i want
Y axis is a mass grain
X axis is a percentage Carbon
and show on a top right like 1st box is a 600, 2nd is a 700 and 3rd is a 800
big thank to everyone

 Akzeptierte Antwort

Scott MacKenzie
Scott MacKenzie am 5 Mär. 2022
Bearbeitet: Scott MacKenzie am 5 Mär. 2022

0 Stimmen

The code below uses your data and generates a bar chart similar to your sketch. I'm not sure how picky you are about the colors. The bar colors below are MATLAB's default.
% data from question
M = [15, 0.000709, 30, 0.00375, 45, 0.002765
15, 0.00015, 30, 0.000261, 45, 0.000344
15, 0.000161, 30, 0.00042, 45, 0.000724];
bar(M(:,[2 4 6])');
set(gca, 'XTickLabel', string(M(1,[1 3 5])));
xlabel('Percent Carbon');
ylabel('Mass Grain');
legend({['800' char(176) 'C'], ['700' char(176) 'C'], ['600' char(176) 'C']});

7 Kommentare

surawut.A
surawut.A am 5 Mär. 2022
appreciate that, thank you very much
surawut.A
surawut.A am 9 Mär. 2022
can I ask 1 more question please,
from your code, how to do a errorbar?
Scott MacKenzie
Scott MacKenzie am 9 Mär. 2022
Bearbeitet: Scott MacKenzie am 9 Mär. 2022
You're welcome. Glad to help. Here's the same code with error bars added:
% data from question
M = [15, 0.000709, 30, 0.00375, 45, 0.002765
15, 0.00015, 30, 0.000261, 45, 0.000344
15, 0.000161, 30, 0.00042, 45, 0.000724];
b = bar(M(:,[2 4 6])');
set(gca, 'XTickLabel', string(M(1,[1 3 5])));
xlabel('Percent Carbon');
ylabel('Mass Grain');
legend({['800' char(176) 'C'], ['700' char(176) 'C'], ['600' char(176) 'C']});
% add error bars
hold on;
xx = [b(1).XEndPoints; b(2).XEndPoints; b(3).XEndPoints];
yy = [b(1).YData; b(2).YData; b(3).YData];
yErr = repmat(0.0001,3,3); % test data for error bars
eb = errorbar(xx, yy, yErr, yErr, 'linestyle', 'none', 'color', 'k', 'linewidth', .8);
set(eb, 'HandleVisibility', 'off');
surawut.A
surawut.A am 9 Mär. 2022
big thank to you again, I really new to this program.
surawut.A
surawut.A am 13 Mär. 2022
sorry again
%------------------------------------------------------
%
%
%------------------------------------------------------
M = [15, 0.000765891, 30, 0.000466818, 45, 0.000770541
15, 0.000709, 30, 0.00375, 45, 0.002765
15, 0.00015, 30, 0.000261, 45, 0.000344
15, 0.000161, 30, 0.00042, 45, 0.000724];
bar(M(:,[2 4 6])');
set(gca, 'XTickLabel', string(M(1,[1 3 5])));
xlabel('%Carbon Monoxide Content');
ylabel('Mass Grain');
legend({['900' char(176) 'C'], ['800' char(176) 'C'], ['700' char(176) 'C'], ['600' char(176) 'C']});
%------------------------------------------------------
% add error bars
%
%------------------------------------------------------
hold on;
xx = [b(1).XEndPoints; b(2).XEndPoints; b(3).XEndPoints; b(4).XEndPoints];
yy = [b(1).YData; b(2).YData; b(3).YData; b(4).YData];
yErr = repmat(0.0001,3,3); % test data for error bars
eb = errorbar(xx, yy, yErr, yErr, 'linestyle', 'none', 'color', 'k', 'linewidth', .8);
set(eb, 'HandleVisibility', 'off');
i add 1 more data at 900C
a graph are running but a code error at error bar
please.
Scott MacKenzie
Scott MacKenzie am 13 Mär. 2022
Bearbeitet: Scott MacKenzie am 13 Mär. 2022
yErr = repmat(0.0001,4,3);
surawut.A
surawut.A am 13 Mär. 2022
I found that I didnt put b = bar 2 4 6
it really a small mistake.
but anyway thank you for helping.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by