I have a function that adds a legend I want to make the legend group certain plots together yet so that instead of a legend with 14 entries there is a legend with 5 entries
I have managed to make a code that automates the plotting of data but I would like the code to group the plots into disticnt groups.
Let us say samples 1,3,5 – is group 1
and 2,4,6- is group 2
7,9,11 group 3
8,10,12 is group 4
and finally 13 & 14 is group 5
this is the code
Nsamples = 7;
%
L = 100; % coupon gauge section (mm)
A = 17; % coupon cross-sectional area (mm^2)
%
figure(1);
hold;
figure(2);
hold
%
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);
%
figure(1)
h(k) = plot(test(k).disp,test(k).force);
set(h(k),’LineWidth’,2);
%
figure(2)
g(k) = plot(test(k).eyy*100,1000*test(k).force/A);
set(g(k),’LineWidth’,2);
%
leg_string{k} = [‘Sample ‘ num2str(k)];
%
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
legend(leg_string,’FontSize’,28,’Interpreter’,’latex’);
%
%
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
legend(leg_string,’FontSize’,28,’Interpreter’,’latex’);
%
%
function [disp,force,eyy] = post_fun(T)
%
disp = table2array(T(:,4));
force = table2array(T(:,end));
eyy = table2array(T(:,10));
%
index = isnan(disp) | isnan(force) | isnan(eyy) | disp < 0 | force < 0 | eyy < 0;
%
disp(index) = [];
force(index) = [];
eyy(index) = [];
%
[~,index] = max(force);
disp(index+1:end) = [];
force(index+1:end) = [];
eyy(index+1:end) = [];
%
end
I have added sample 1-7 . csv but the code doesn’t seem to run on this page.
this is what the figure1+2 looks like
Hopefully you can help.
Thanks
AlexI have managed to make a code that automates the plotting of data but I would like the code to group the plots into disticnt groups.
Let us say samples 1,3,5 – is group 1
and 2,4,6- is group 2
7,9,11 group 3
8,10,12 is group 4
and finally 13 & 14 is group 5
this is the code
Nsamples = 7;
%
L = 100; % coupon gauge section (mm)
A = 17; % coupon cross-sectional area (mm^2)
%
figure(1);
hold;
figure(2);
hold
%
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);
%
figure(1)
h(k) = plot(test(k).disp,test(k).force);
set(h(k),’LineWidth’,2);
%
figure(2)
g(k) = plot(test(k).eyy*100,1000*test(k).force/A);
set(g(k),’LineWidth’,2);
%
leg_string{k} = [‘Sample ‘ num2str(k)];
%
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
legend(leg_string,’FontSize’,28,’Interpreter’,’latex’);
%
%
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
legend(leg_string,’FontSize’,28,’Interpreter’,’latex’);
%
%
function [disp,force,eyy] = post_fun(T)
%
disp = table2array(T(:,4));
force = table2array(T(:,end));
eyy = table2array(T(:,10));
%
index = isnan(disp) | isnan(force) | isnan(eyy) | disp < 0 | force < 0 | eyy < 0;
%
disp(index) = [];
force(index) = [];
eyy(index) = [];
%
[~,index] = max(force);
disp(index+1:end) = [];
force(index+1:end) = [];
eyy(index+1:end) = [];
%
end
I have added sample 1-7 . csv but the code doesn’t seem to run on this page.
this is what the figure1+2 looks like
Hopefully you can help.
Thanks
Alex I have managed to make a code that automates the plotting of data but I would like the code to group the plots into disticnt groups.
Let us say samples 1,3,5 – is group 1
and 2,4,6- is group 2
7,9,11 group 3
8,10,12 is group 4
and finally 13 & 14 is group 5
this is the code
Nsamples = 7;
%
L = 100; % coupon gauge section (mm)
A = 17; % coupon cross-sectional area (mm^2)
%
figure(1);
hold;
figure(2);
hold
%
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);
%
figure(1)
h(k) = plot(test(k).disp,test(k).force);
set(h(k),’LineWidth’,2);
%
figure(2)
g(k) = plot(test(k).eyy*100,1000*test(k).force/A);
set(g(k),’LineWidth’,2);
%
leg_string{k} = [‘Sample ‘ num2str(k)];
%
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
legend(leg_string,’FontSize’,28,’Interpreter’,’latex’);
%
%
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
legend(leg_string,’FontSize’,28,’Interpreter’,’latex’);
%
%
function [disp,force,eyy] = post_fun(T)
%
disp = table2array(T(:,4));
force = table2array(T(:,end));
eyy = table2array(T(:,10));
%
index = isnan(disp) | isnan(force) | isnan(eyy) | disp < 0 | force < 0 | eyy < 0;
%
disp(index) = [];
force(index) = [];
eyy(index) = [];
%
[~,index] = max(force);
disp(index+1:end) = [];
force(index+1:end) = [];
eyy(index+1:end) = [];
%
end
I have added sample 1-7 . csv but the code doesn’t seem to run on this page.
this is what the figure1+2 looks like
Hopefully you can help.
Thanks
Alex plot, figure, legend MATLAB Answers — New Questions