Please explain the following code for me !!!

2 views (last 30 days)
function createfigure(cdata1, X1, Y1, X2, Y2)
%CREATEFIGURE(cdata1, X1, Y1, X2, Y2)
% CDATA1: image cdata
% X1: vector of x data
% Y1: vector of y data
% X2: vector of x data
% Y2: vector of y data
% Auto-generated by MATLAB on 06-Nov-2021 14:39:07
% Create figure
figure1 = figure('Tag','RobotSimulator','Name','Robot Simulator');
% Create axes
axes1 = axes('Parent',figure1);
% Create image
image([0.00373412994772218 9.99626587005228],...
[4.24570575056012 0.00373412994772218],cdata1,'Parent',axes1,...
% Create plot
plot(X1,Y1,'ZDataSource','','Color',[1 0 0]);
% Create plot
plot(X2,Y2,'ZDataSource','','MarkerFaceColor',[1 1 1],'Marker','o',...
'Color',[0 0 1]);
% Create ylabel
ylabel('Y [meters]');
% Create xlabel
xlabel('X [meters]');
% Create title
title('Circle = robot position, Line = robot orientation');
% Uncomment the following line to preserve the X-limits of the axes
% xlim(axes1,[0 10]);
% Uncomment the following line to preserve the Y-limits of the axes
% ylim(axes1,[0 4.24943988050784]);
% Set the remaining axes properties
set(axes1,'DataAspectRatio',[1 1 1],'Layer','top','TickDir','out');
This is the code in FIGURE, used to simulate the robot moving on the map, hope everyone can explain this code to me
And how to put this code in the GUI ?

Accepted Answer

Sudharsana Iyengar
Sudharsana Iyengar on 6 Nov 2021
You have generated code using generate code in the file menu of your figure.
So next time when you want to make a figure of this robot you will have to supply the cdata, x1,y1,x2and y2. Using the data as arguments, your createfigure function will create a plot.
To put this in code in GUI, you will have to make 5 inputs which will take the cdata, x1,y1,x2,y2. Then when you push the push button, this function should be called and a figure should be generated on the axes.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!