Generated Code from plot

50 views (last 30 days)
Pranoy Mitra
Pranoy Mitra on 14 Nov 2020
Edited: Cris LaPierre on 14 Nov 2020
How to implement the generated code from the plot inspector?
Code:
function createfigure6(X1, Y1, X2, Y2, X3, Y3, X4, YMatrix1, X5, Y4, X6, YMatrix2)
%CREATEFIGURE6(X1, Y1, X2, Y2, X3, Y3, X4, YMatrix1, X5, Y4, X6, YMatrix2)
% X1: vector of x data
% Y1: vector of y data
% X2: vector of x data
% Y2: vector of y data
% X3: vector of x data
% Y3: vector of y data
% X4: vector of x data
% YMATRIX1: matrix of y data
% X5: vector of x data
% Y4: vector of y data
% X6: vector of x data
% YMATRIX2: matrix of y data
% Auto-generated by MATLAB on 14-Nov-2020 12:23:36
% Create figure
figure1 = figure('WindowState','maximized');
% Create axes
axes1 = axes('Parent',figure1);
hold(axes1,'on');
% Create plot
plot(X1,Y1,'DisplayName','All Datapoints Set 1','Marker','.',...
'LineStyle','none',...
'Color',[0.8 0.79 0.79]);
% Create plot
plot(X2,Y2,'DisplayName','All Datapoints Set 2','Marker','.',...
'LineStyle','none',...
'Color',[0.8 0.79 0.79]);
% Create plot
plot(X3,Y3,'DisplayName','Datapoints Set 1','Marker','.','LineStyle','none',...
'Color',[0.529411764705882 0.709803921568627 0.980392156862745]);
% Create multiple lines using matrix input to plot
plot1 = plot(X4,YMatrix1,'DisplayName','Mean Fit-Error Set 1',...
'PickableParts','none',...
'HitTest','off',...
'LineWidth',1.5,...
'Color',[0.011764705882353 0.27843137254902 0.701960784313725],...
'Parent',axes1,...
'AlignVertexCenters','on',...
'LineStyle','--');
set(plot1(1),'DisplayName','Datapoints Set 1','LineWidth',2,...
'AlignVertexCenters','off',...
'LineStyle','-');
set(plot1(3),'MarkerFaceColor','auto');
% Create plot
plot(X5,Y4,'DisplayName','Datapoints Set 2','MarkerFaceColor','auto',...
'Marker','.',...
'LineStyle','none',...
'Color',[0.980392156862745 0.388235294117647 0.388235294117647]);
% Create multiple lines using matrix input to plot
plot2 = plot(X6,YMatrix2,'DisplayName','Mean Fit-Error Set 2',...
'PickableParts','none',...
'HitTest','off',...
'LineWidth',1.5,...
'Color',[1 0 0],...
'Parent',axes1,...
'AlignVertexCenters','on',...
'LineStyle','--');
set(plot2(1),'DisplayName','Datapoints Set 2','LineWidth',2,...
'AlignVertexCenters','off',...
'LineStyle','-');
% Create ylabel
ylabel('Slipslide angel Beta[^0]','Interpreter','none');
% Create xlabel
xlabel('Lateral acceleration[m/s^2]','Interpreter','none');
box(axes1,'on');
% Create legend
legend1 = legend(axes1,'show');
set(legend1,'Location','best');
end

Accepted Answer

Cris LaPierre
Cris LaPierre on 14 Nov 2020
Edited: Cris LaPierre on 14 Nov 2020
It has created a plotting funciton for you. Once you save it, you can use it to recreate your plot. Since it is a function you will need to create the inputs first. You would know better than us what those inputs should be, but a brief description is included at the top of your function. Keep in mind that
  • Vectors X1 and Y1 must have the same length
  • Vectors X2 and Y2 must have the same length
  • Vectors X3 and Y3 must have the same length
  • The length of X4 must be the same as the number of rows in YMatrix1
  • Vectors X5 and Y4 must have the same length
  • The length of X6 must be the same as the number of rows in YMatrix2
Calling it might look something like this.
X1 = 0:10;
Y1 = X1;
X2 = 0:10;
Y2 = X2/2;
X3 = 0:10;
Y3 = 10-X3;
X4 = 0:10;
YMatrix1 = rand([length(X4),3]);
X5 = 0:10;
Y4 = 10-X5/2;
X6 = 0:10;
YMatrix2 = randi(10,[length(X6),2]);
% call function
createfigure6(X1, Y1, X2, Y2, X3, Y3, X4, YMatrix1, X5, Y4, X6, YMatrix2)

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!