I want to add two histograms with error bars to a piece of code I already have that is generating two plots
I have a piece of code that is currently calculating stress/strain and force/extension.
It groups them into catagories based on the temperature and time they were sintered for.
I would like to add histograsm that can also show the modulus of elasticity and the ultimate tensile strength for these groups. The modulus of elasticity should be for say a range from ~0.05 to 0.15 extension, or similar. The error bars should show +/- the stdev for the data sets
would also like to make it so that the legend expressly states the sintering cycle.
For example ‘conventional sintering’ two-stage sintering’, ‘sintered at x°C for x hours’ etc
below is the code
clear
close all
Nsamples = 14;
G=ones(1,2*Nsamples);
G(1:12)=1;
G([2:1:4 10:1:11])=2;
G(5:1:9)=3;
G(13:14)=4;
%%
load(‘E:DICsintering_dataOXmcdata.mat’)
% G(15)=5;
% G(16)=6;
% G(13:14)=5;
% M={‘x’,’+’,’*’,’s’,’d’}; % a marker for each group
C={‘r’,’b’,’m’,’g’,’m’,’y’}; % and a color
L = 90; % coupon gauge section (mm)
A = 18; % coupon cross-sectional area (mm^2)
figure(1);
hold on
figure(2);
hold on
for k = 1:Nsamples
file_name = [‘Sample’ num2str(k) ‘.csv’];
T = readtable(file_name,’VariableNamingRule’,’preserve’);
[test(k).disp,test(k).force,test(k).eyy] = post_fun(T);
ig=G(k); % get group id for kth file
figure(1)
% h(k) = plot(test(k).disp,test(k).force,’LineWidth’,2,’Marker’,M(ig),’Color’,C{ig});
h(k) = plot(test(k).disp,test(k).force,’LineWidth’,2,’Color’,C{ig});
figure(2)
% g(k) = plot(test(k).eyy*100,1000*test(k).force/A,’LineWidth’,2,’Marker’,M(ig),’Color’,C{ig});
g(k) = plot(test(k).eyy*100,1000*test(k).force/A,’LineWidth’,2,’Color’,C{ig});
leg_string{k} = [‘Sintering schedule ‘ num2str(ig)];
end
%
%%
figure(1)
set(gcf,’Position’,[200 200 1024 768],’Color’,[1 1 1]);
set(gca,’FontSize’,24);
xlabel(‘Displacement (mm)’,’FontSize’,32,’Interpreter’,’latex’);
ylabel(‘Force (kN)’,’FontSize’,32,’Interpreter’,’latex’);
box on
grid on
title(‘Force / extension curves for of various sintering schedules’,’FontSize’, 20,’Interpreter’,’latex’)
legend(h([1 2 5 13]),leg_string([1 2 5 13]),’FontSize’,28,’Interpreter’,’latex’,’location’,’southeast’);
%%
figure(2)
set(gcf,’Position’,[200 200 1024 768],’Color’,[1 1 1]);
set(gca,’FontSize’,24);
xlabel(‘Strain (%)’,’FontSize’,32,’Interpreter’,’latex’);
ylabel(‘Stress (MPa)’,’FontSize’,32,’Interpreter’,’latex’);
box on
grid on
title(‘Stress / strain curves for of various sintering schedules’,’FontSize’, 20,’Interpreter’,’latex’)
legend(g([1 2 5 13]),leg_string([1 2 5 13]),’FontSize’,28,’Interpreter’,’latex’,’location’,’southeast’);
%
plot(OXmcdata(:,1),OXmcdata(:,2),’DisplayName’,’Farhandi et al (2021)’,’LineWidth’,3,’Color’,’k’,’LineStyle’,’–‘);
%
xlim([0 3E-1]);
ylim([0 350]);
%%
function [displ,force,eyy] = post_fun(T)
displ=T{:,4};
force=T{:,end};
eyy =T{:,10};
ix=all(isfinite([displ force eyy]),2) & all([displ force eyy]>0,2);
displ=displ(ix);
force=force(ix);
eyy=eyy(ix);
[~,imax] = max(force);
displ(imax+1:end) = [];
force(imax+1:end) = [];
eyy(imax+1:end) = [];
end
Hopefully you can help.
Thanks
AlexI have a piece of code that is currently calculating stress/strain and force/extension.
It groups them into catagories based on the temperature and time they were sintered for.
I would like to add histograsm that can also show the modulus of elasticity and the ultimate tensile strength for these groups. The modulus of elasticity should be for say a range from ~0.05 to 0.15 extension, or similar. The error bars should show +/- the stdev for the data sets
would also like to make it so that the legend expressly states the sintering cycle.
For example ‘conventional sintering’ two-stage sintering’, ‘sintered at x°C for x hours’ etc
below is the code
clear
close all
Nsamples = 14;
G=ones(1,2*Nsamples);
G(1:12)=1;
G([2:1:4 10:1:11])=2;
G(5:1:9)=3;
G(13:14)=4;
%%
load(‘E:DICsintering_dataOXmcdata.mat’)
% G(15)=5;
% G(16)=6;
% G(13:14)=5;
% M={‘x’,’+’,’*’,’s’,’d’}; % a marker for each group
C={‘r’,’b’,’m’,’g’,’m’,’y’}; % and a color
L = 90; % coupon gauge section (mm)
A = 18; % coupon cross-sectional area (mm^2)
figure(1);
hold on
figure(2);
hold on
for k = 1:Nsamples
file_name = [‘Sample’ num2str(k) ‘.csv’];
T = readtable(file_name,’VariableNamingRule’,’preserve’);
[test(k).disp,test(k).force,test(k).eyy] = post_fun(T);
ig=G(k); % get group id for kth file
figure(1)
% h(k) = plot(test(k).disp,test(k).force,’LineWidth’,2,’Marker’,M(ig),’Color’,C{ig});
h(k) = plot(test(k).disp,test(k).force,’LineWidth’,2,’Color’,C{ig});
figure(2)
% g(k) = plot(test(k).eyy*100,1000*test(k).force/A,’LineWidth’,2,’Marker’,M(ig),’Color’,C{ig});
g(k) = plot(test(k).eyy*100,1000*test(k).force/A,’LineWidth’,2,’Color’,C{ig});
leg_string{k} = [‘Sintering schedule ‘ num2str(ig)];
end
%
%%
figure(1)
set(gcf,’Position’,[200 200 1024 768],’Color’,[1 1 1]);
set(gca,’FontSize’,24);
xlabel(‘Displacement (mm)’,’FontSize’,32,’Interpreter’,’latex’);
ylabel(‘Force (kN)’,’FontSize’,32,’Interpreter’,’latex’);
box on
grid on
title(‘Force / extension curves for of various sintering schedules’,’FontSize’, 20,’Interpreter’,’latex’)
legend(h([1 2 5 13]),leg_string([1 2 5 13]),’FontSize’,28,’Interpreter’,’latex’,’location’,’southeast’);
%%
figure(2)
set(gcf,’Position’,[200 200 1024 768],’Color’,[1 1 1]);
set(gca,’FontSize’,24);
xlabel(‘Strain (%)’,’FontSize’,32,’Interpreter’,’latex’);
ylabel(‘Stress (MPa)’,’FontSize’,32,’Interpreter’,’latex’);
box on
grid on
title(‘Stress / strain curves for of various sintering schedules’,’FontSize’, 20,’Interpreter’,’latex’)
legend(g([1 2 5 13]),leg_string([1 2 5 13]),’FontSize’,28,’Interpreter’,’latex’,’location’,’southeast’);
%
plot(OXmcdata(:,1),OXmcdata(:,2),’DisplayName’,’Farhandi et al (2021)’,’LineWidth’,3,’Color’,’k’,’LineStyle’,’–‘);
%
xlim([0 3E-1]);
ylim([0 350]);
%%
function [displ,force,eyy] = post_fun(T)
displ=T{:,4};
force=T{:,end};
eyy =T{:,10};
ix=all(isfinite([displ force eyy]),2) & all([displ force eyy]>0,2);
displ=displ(ix);
force=force(ix);
eyy=eyy(ix);
[~,imax] = max(force);
displ(imax+1:end) = [];
force(imax+1:end) = [];
eyy(imax+1:end) = [];
end
Hopefully you can help.
Thanks
Alex I have a piece of code that is currently calculating stress/strain and force/extension.
It groups them into catagories based on the temperature and time they were sintered for.
I would like to add histograsm that can also show the modulus of elasticity and the ultimate tensile strength for these groups. The modulus of elasticity should be for say a range from ~0.05 to 0.15 extension, or similar. The error bars should show +/- the stdev for the data sets
would also like to make it so that the legend expressly states the sintering cycle.
For example ‘conventional sintering’ two-stage sintering’, ‘sintered at x°C for x hours’ etc
below is the code
clear
close all
Nsamples = 14;
G=ones(1,2*Nsamples);
G(1:12)=1;
G([2:1:4 10:1:11])=2;
G(5:1:9)=3;
G(13:14)=4;
%%
load(‘E:DICsintering_dataOXmcdata.mat’)
% G(15)=5;
% G(16)=6;
% G(13:14)=5;
% M={‘x’,’+’,’*’,’s’,’d’}; % a marker for each group
C={‘r’,’b’,’m’,’g’,’m’,’y’}; % and a color
L = 90; % coupon gauge section (mm)
A = 18; % coupon cross-sectional area (mm^2)
figure(1);
hold on
figure(2);
hold on
for k = 1:Nsamples
file_name = [‘Sample’ num2str(k) ‘.csv’];
T = readtable(file_name,’VariableNamingRule’,’preserve’);
[test(k).disp,test(k).force,test(k).eyy] = post_fun(T);
ig=G(k); % get group id for kth file
figure(1)
% h(k) = plot(test(k).disp,test(k).force,’LineWidth’,2,’Marker’,M(ig),’Color’,C{ig});
h(k) = plot(test(k).disp,test(k).force,’LineWidth’,2,’Color’,C{ig});
figure(2)
% g(k) = plot(test(k).eyy*100,1000*test(k).force/A,’LineWidth’,2,’Marker’,M(ig),’Color’,C{ig});
g(k) = plot(test(k).eyy*100,1000*test(k).force/A,’LineWidth’,2,’Color’,C{ig});
leg_string{k} = [‘Sintering schedule ‘ num2str(ig)];
end
%
%%
figure(1)
set(gcf,’Position’,[200 200 1024 768],’Color’,[1 1 1]);
set(gca,’FontSize’,24);
xlabel(‘Displacement (mm)’,’FontSize’,32,’Interpreter’,’latex’);
ylabel(‘Force (kN)’,’FontSize’,32,’Interpreter’,’latex’);
box on
grid on
title(‘Force / extension curves for of various sintering schedules’,’FontSize’, 20,’Interpreter’,’latex’)
legend(h([1 2 5 13]),leg_string([1 2 5 13]),’FontSize’,28,’Interpreter’,’latex’,’location’,’southeast’);
%%
figure(2)
set(gcf,’Position’,[200 200 1024 768],’Color’,[1 1 1]);
set(gca,’FontSize’,24);
xlabel(‘Strain (%)’,’FontSize’,32,’Interpreter’,’latex’);
ylabel(‘Stress (MPa)’,’FontSize’,32,’Interpreter’,’latex’);
box on
grid on
title(‘Stress / strain curves for of various sintering schedules’,’FontSize’, 20,’Interpreter’,’latex’)
legend(g([1 2 5 13]),leg_string([1 2 5 13]),’FontSize’,28,’Interpreter’,’latex’,’location’,’southeast’);
%
plot(OXmcdata(:,1),OXmcdata(:,2),’DisplayName’,’Farhandi et al (2021)’,’LineWidth’,3,’Color’,’k’,’LineStyle’,’–‘);
%
xlim([0 3E-1]);
ylim([0 350]);
%%
function [displ,force,eyy] = post_fun(T)
displ=T{:,4};
force=T{:,end};
eyy =T{:,10};
ix=all(isfinite([displ force eyy]),2) & all([displ force eyy]>0,2);
displ=displ(ix);
force=force(ix);
eyy=eyy(ix);
[~,imax] = max(force);
displ(imax+1:end) = [];
force(imax+1:end) = [];
eyy(imax+1:end) = [];
end
Hopefully you can help.
Thanks
Alex histogram, bar, error, errorbars MATLAB Answers — New Questions