Study notes-Matlab two-dimensional drawing

2D drawing

plot

function epx_plt1
    years=1994:2000;
    income=[8 12 20 22 18 24 27];
    plot(years,income,'--r<','linewidth',2,'markersize',12,'markerfacecolor','w','markeredgecolor','b')
end

%%linewidth:线宽
%%markersize:节点大小
%%markeredgecolor:节点边缘颜色
%%markerfacecolor:节点填充颜色
%
节点类型:
+:加号
o:圆
*:星号
.:点
x:叉号
^:正三角形
v:倒三角形
s:四边形
d:菱形
p:五边形
h:六边形
<:左三角形
>:右三角形
%

%
线型类型:
-:实线
--:虚线
::点式虚线
-.:点线虚线
r:红色
g:绿色
b:黑色
y:黄色
k:黑色
w:白色
%

 hold on/hold off

x=-2:0.01:4;
y=3*x.^3-26*x+6;
y2=9*x.^2-25;
y3=17*x;

plot(x,y,'-b');
hold on;
plot(x,y2,'--g');
plot(x,y3,'-.r');
hold off;

%%hold on 表示继续在该图中绘制

%%也可以使用line(x,y)进行绘制,它使用向量 x 和 y 中的数据在当前坐标区中绘制线条

Labeling

%xlabel('text'):x轴标签
%ylabel('text'):y轴标签
%title('text'):标题
%text(x,y,'text'):指定位置的文字
%gtext('text'):图内某位在写入文字
%legend('str1','str2','str3',...,pos):图例区分

%其中pos可以取:
%-1:图例外,置于右侧
%0:图例内,置于最佳位置
%1:右上;2:左上;3:左下;4:右下


x=10:0.1:22;
y=95450./x.^2;
x2=10:2:22;
y2=[950 640 460 340 250 180 140];
plot(x,y,'-','linewidth',1)
xlabel('Distance(cm)')
ylabel('Intensity(lux)')
title('','fontsize',14);
axis([8 24 0 1200]);

%%    axis([xmin,xmax,ymin,ymax])用于设定坐标轴范围

text(14,700,'Comparison between theory and experiment.','edgecolor','r','linewidth',2);

hold on
plot(x2,y2,'ro--','linewidth',1,'markersize',10);
legend('Theory','Experiment');
hold off;

Input of special symbols

\alpha
\beta
\gamma
\theta
\pi
\sigma
\phi
\Delta
\Gamma
\Lambda
\Omega
\Sigma

Logarithmic axis: semilogx(x,y)

figure
x=linspace(0.1,60,1000);
y=2.^(-0.2*x+10);
plot(x,y);

figure
semilogx(x,y);

 errorbar

x=10:2:22;
y=[950 640 460 340 250 180 140];
err=[30 20 18 34 21 32 12];
errorbar(x,y,err);
xlabel('Distance(cm)');
ylabel('Intensity(lux)');

Histogram: bar(x,y),barh(x,y)

x=1988:1994;
sle=[8 12 20 22 18 24 27];
figure
bar(x,sle,'r');
xlabel('Year');
ylabel('Sales');

figure
barh(x,sle,'b');
xlabel('Year');
ylabel('Sales');

Pie chart: pie(x)

g=[11 18 26 9 5];
pie(g);
title('Class Grades');

 

 Ladder diagram stairs(x,y)

x=1988:1994;
sle=[8 12 20 22 18 24 27];
stairs(x,sle);

Match map: stem(x,y)

x=1988:1994;
sle=[8 12 20 22 18 24 27];
stem(x,sle);

Statistical histogram histogram(y,n)

y=[58 43 44 55 67 55 44 56 66 76 98 76 55 34 56 76 87 89 78 67 54 56 78 90 87 99 75 56 87];
histogram(y,8);

 

 Polar plot: polarplot(t,r)

t=linspace(0,2*pi,200);
r=3*cos(0.5*t).^2+t;
polarplot(t,r);

Subplot: subplot()

x = 0:0.2:10;
y1 = x.^2;
y2 = x.^3;
y3=x.^4;
y4=x;
subplot(2,2,1)
plot(x,y1)
subplot(2,2,2);
plot(x,y2)
subplot(2,2,3);
plot(x,y3);
subplot(2,2,4);
plot(x,y4);

clc
clear
syms t Px Py Pz;
R=400;r=100;l1=300;l2=1050;
alpha1=(1-1)*2*pi/3-pi/6;
alpha2=(2-1)*2*pi/3-pi/6;
alpha3=(3-1)*2*pi/3-pi/6;

Px=0.1*sin(2*pi*t);
Py=0.1*cos(2*pi*t);
Pz=-0.72;
theta1=zeros(1,100);
theta2=zeros(1,100);
theta3=zeros(1,100);

    Px=800*sin(2.5*pi*t);
    Py=800*cos(2.5*pi*t);
    Pz=-750;
    D1=2*l1*((Px+r*cos(alpha1)-R*cos(alpha1))*cos(alpha1)+(Py+r*sin(alpha1)-R*sin(alpha1))*sin(alpha1));
    D2=2*l1*((Px+r*cos(alpha2)-R*cos(alpha2))*cos(alpha2)+(Py+r*sin(alpha2)-R*sin(alpha2))*sin(alpha2));
    D3=2*l1*((Px+r*cos(alpha3)-R*cos(alpha3))*cos(alpha3)+(Py+r*sin(alpha3)-R*sin(alpha3))*sin(alpha3));

    E1=2*l1*Pz;
    E2=2*l1*Pz;
    E3=2*l1*Pz;

    F1=((Px+r*cos(alpha1)-R*cos(alpha1)))^2+((Py+r*sin(alpha1)-R*sin(alpha1)))^2+Pz^2+l1^2-l2^2;
    F2=((Px+r*cos(alpha2)-R*cos(alpha2)))^2+((Py+r*sin(alpha2)-R*sin(alpha2)))^2+Pz^2+l1^2-l2^2;
    F3=((Px+r*cos(alpha3)-R*cos(alpha3)))^2+((Py+r*sin(alpha3)-R*sin(alpha3)))^2+Pz^2+l1^2-l2^2;


    theta1=2*atan((-E1-sqrt(E1^2-F1^2+D1^2))/(F1+D1));
    
    theta2=2*atan((-E2-sqrt(E2^2-F2^2+D2^2))/(F2+D2));
     
    theta3=2*atan((-E3-sqrt(E3^2-F3^2+D3^2))/(F3+D3));
    
    atheta1=diff(theta1,t);
    atheta2=diff(theta2,t);
    atheta3=diff(theta3,t);

    


t=1:0.01:2;

atheta1=eval(atheta1);
atheta2=eval(atheta2);
atheta3=eval(atheta3);

theta1=eval(theta1);
theta2=eval(theta2);
theta3=eval(theta3);

subplot(1,3,1)
hold on
plot(t,atheta1,'r','linewidth',1.5);
plot(t,atheta2,'--g','linewidth',1.5);
plot(t,atheta3,':b','linewidth',1.5);
hold off
legend('atheta1','atheta2','atheta3')
ylabel('主动臂角速度rad/s^2');
xlabel('时间t/s');
title('主动臂角速度随时间的变化关系');
grid on

subplot(1,3,2)
hold on
plot(t,theta1,'r','linewidth',1.5);
plot(t,theta2,'--g','linewidth',1.5);
plot(t,theta3,':b','linewidth',1.5);
hold off
legend('theta1','theta1','theta1')
ylabel('主动臂转角rad');
xlabel('时间t/s');
title('主动臂转角随时间的变化关系');
hold off
grid on


subplot(1,3,3)
hold on
plot(t,800*sin(2.1*pi*t),'r','linewidth',1.5);
plot(t,800*cos(2.1*pi*t),'--g','linewidth',1.5);
hold off
legend('Px','Py')
ylabel('末端位置Px/Py');
xlabel('时间t/s');
title('末端位置Px/Py随时间的变化关系');
hold off
grid on

  

 

Guess you like

Origin blog.csdn.net/seek97/article/details/108293269