Please explain the following code for me !!!
2 views (last 30 days)
Show older comments
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);
hold(axes1,'on');
% Create image
image([0.00373412994772218 9.99626587005228],...
[4.24570575056012 0.00373412994772218],cdata1,'Parent',axes1,...
'CDataMapping','scaled');
% Create plot
plot(X1,Y1,'ZDataSource','','Color',[1 0 0]);
% Create plot
plot(X2,Y2,'ZDataSource','','MarkerFaceColor',[1 1 1],'Marker','o',...
'LineStyle','none',...
'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]);
box(axes1,'on');
% 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 ?
0 Comments
Accepted Answer
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.
3 Comments
Sudharsana Iyengar
on 7 Nov 2021
This shows the method. Instead of xls you can use any other data file. This discusses on how gui is made. Instead of 2 you may have to include 5 inputs. Check it out.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!