How to plot the subplots but with less lines of code?
Show older comments
Hi,
I am plotting the 4 graphs in subplotting using the code below. but I want to use less amount of lines. Code is below!
Code:
files = ['F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_Head\Data_Raw\LaserSheet.xlsx'];
a = readtable(files);
x = a{:,16};
y = a{:,15};
files = ['F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_C\Data_Head\Data_Raw\LaserSheet.xlsx']
a = readtable(files);
x1 = a{:,16};
y1 = a{:,15};
files = ['F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_B\Data_Head\Data_Raw\LaserSheet.xlsx'];
a = readtable(files);
x2 = a{:,16};
y2 = a{:,15};
files = ['F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_A\Data_Head\Data_Raw\LaserSheet.xlsx'];
a = readtable(files);
x3 = a{:,16};
y3 = a{:,15};
figure()
subplot(2,2,1)
plot(x,y,'*')
%Spacing and griding
xlim([0 6])
ylim([0 600])
hold on
grid on
% Design Head
y = 500;
line ([0,500],[y,y],'color','k','LineWidth',1);
txt = {'Design Head = 500 mm'};
text(1,560,txt)
x = 5;
line ([x,x],[0,500],'color','k','LineWidth',1);
%Chart Representation
title('DataLaserSheet-D');
xlabel('flowrate (l/s)');
ylabel('Head (mm))');
hold on
subplot(2,2,2)
plot(x1,y1,'*')
%Spacing and griding
xlim([0 6])
ylim([0 600])
hold on
grid on
% Design Head
y = 500; %17 mm
line ([0,500],[y,y],'color','k','LineWidth',1);
txt = {'Design Head = 500 mm'};
text(1,560,txt)
x = 5;
line ([x,x],[0,500],'color','k','LineWidth',1);
%Chart Representation
title('DataLaserSheet-C');
xlabel('flowrate (l/s)');
ylabel('Head (mm))');
hold on
subplot(2,2,3)
plot(x2,y2,'*')
hold on
%Spacing and griding
xlim([0 6])
ylim([0 600])
hold on
grid on
% Design Head
y = 500; %17 mm
line ([0,500],[y,y],'color','k','LineWidth',1);
txt = {'Design Head = 500 mm'};
text(1,560,txt)
x = 5;
line ([x,x],[0,500],'color','k','LineWidth',1);
%Chart Representation
title('DataLaserSheet-B');
xlabel('flowrate (l/s)');
ylabel('Head (mm))');
subplot(2,2,4)
plot(x3,y3,'*')
hold on
%Spacing and griding
xlim([0 6])
ylim([0 600])
hold on
grid on
%Design,Kickback and Flushflow ppoints
% Design Head
y = 500; %17 mm
line ([0,500],[y,y],'color','k','LineWidth',1);
txt = {'Design Head = 500 mm'};
text(1,560,txt)
x = 5;
line ([x,x],[0,500],'color','k','LineWidth',1);
%Chart Representation
title('DataLaserSheet-A');
xlabel('flowrate (l/s)');
ylabel('Head (mm))');
%over all chart title
sgtitle('Outlet-110 mm')
Accepted Answer
More Answers (1)
Image Analyst
on 14 Jan 2022
Try using the nexttile() function
nexttile;
instead of the subplot() function
subplot(2, 3, j)
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!