matlab中stem_MATLAB发布代码---生成文档pdf

9f4d6031cd895a0081746af314dde7a0.png

1、前记:

发布 MATLAB® 代码文件 (.m) 可创建包括您的代码、注释和输出的格式化文档。发布代码的常见原因是与其他人共享文档以用于教学或演示,或者生成您代码的可读外部文档。要在 MATLAB 编辑器中创建同时包含您的代码、格式化内容和输出的交互式文档,请参阅在实时编辑器中创建实时脚本。

2、步骤----打开要发布的代码文件(m文件)-----点击发布----选择编辑发布选项。如下:

306c481da503f22a0e707c1469b1a4e7.png

点击输出文件,选择格式和修改地址,点击发布

4b9bbbb27ad66c939c4039ebb55bad95.png

如:源代码为 Robotics System Toolbox中的机器人运动 (3)中的例子


%% Waypoint tracking demonstration using Robotics System Toolbox

% This demonstration performs inverse kinematics of a

% robot manipulator to follow a desired set of waypoints.

% Copyright 2017-2018 The MathWorks, Inc.

%% Load and display robot

clear

clc

robot = importrobot('irb_140.urdf');

axis([-0.6 0.8 -0.6 0.65 0 1.2]);

show(robot);

axes.CameraPositionMode = 'auto';

%% Create a set of desired wayPoints

wayPoints = [0.5 0.1 0.6;0.5 0.4 0.5]; % Alternate set of wayPoints

%wayPoints = [0.2 -0.2 0.02;0.15 0 0.28;0.15 0.05 0.2; 0.15 0.09 0.15;0.1 0.12 0.1; 0.04 0.1 0.2;0.25 0 0.15; 0.2 0.2 0.02];

exampleHelperPlotWaypoints(wayPoints);

%% Create a smooth curve from the waypoints to serve as trajectory

trajectory = cscvn(wayPoints');%在点之间创建轨迹

% Plot trajectory spline and waypoints

hold on

fnplt(trajectory,'r',2);



%% Perform Inverse Kinematics for a point in space

% Add end effector frame, offset from the grip link frame

eeOffset = 0.01;

eeBody = robotics.RigidBody('end_effector');

setFixedTransform(eeBody.Joint,trvec2tform([eeOffset 0 0]));

addBody(robot,eeBody,'link_6');

ik = robotics.InverseKinematics('RigidBodyTree',robot);

weights = [0.1 0.1 0 1 1 1];

initialguess = robot.homeConfiguration;

% Calculate the inverse kinematic solution using the "ik" solver 

% Use desired weights for solution (First three are orientation, last three are translation)

% Since it is a 4-DOF robot with only one revolute joint in Z we do not

% put a weight on Z rotation; otherwise it limits the solution space

numTotalPoints =40;

% Evaluate trajectory to create a vector of end-effector positions

eePositions = ppval(trajectory,linspace(0,trajectory.breaks(end),numTotalPoints));

% Call inverse kinematics solver for every end-effector position using the

% previous configuration as initial guess

for idx = 1:size(eePositions,2)

    tform = trvec2tform(eePositions(:,idx)');

    configSoln(idx,:) = ik('end_effector',tform,weights,initialguess);

    initialguess = configSoln(idx,:);

end

%% Visualize robot configurations

title('Robot waypoint tracking visualization')

hold on

axis([-0.6 0.8 -0.6 0.65 0 1.3]);

for idx = 1:size(eePositions,2)

    show(robot,configSoln(idx,:), 'PreservePlot', false,'Frames','off');

    pause(0.1)

end

%% Plot joints values

A = cat(1,configSoln.JointPosition);

clf

figure

stem(A)%overview

%% Joints

joint1=A(1:40,1);

joint2=A(41:80,1);

joint3=A(81:120,1);

joint4=A(121:160,1);

joint5=A(161:200,1);

joint6=A(201:240,1);

figure

stem(joint1,'LineStyle','none','MarkerFaceColor','r','MarkerEdgeColor','g')

title('Joint关节的值变化')

hold on

stem(joint2,'LineStyle','none','MarkerFaceColor','g','MarkerEdgeColor','b')

stem(joint3,'LineStyle','none','MarkerFaceColor','b','MarkerEdgeColor','y')

stem(joint4,'LineStyle','none','MarkerFaceColor','y','MarkerEdgeColor','m')

stem(joint5,'LineStyle','none','MarkerFaceColor','c','MarkerEdgeColor','w')

stem(joint6,'LineStyle','none','MarkerFaceColor','m','MarkerEdgeColor','b')

发布后生成的PDF文档效果为:

458252ec54532d52f4b24e25db76d0e7.png

3、后记:figure图框的利用---打印图窗、点击箭头修改图占框大小、插入图例修改data标签,以便给论文提取所需的图。

7f75a91b306b7f4e461ba143a80d6a04.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值