matlab 绘制符号函数,DAY8 MATLAB学习笔记—simulink入门、MATLAB符号函数的图形绘制...

如何打开simulink:

启动simulink:

先打开MATLAB软件界面

第一步打开simulink

第二步在command windows输入 simulink然后enter,等待

有很多模块库

第三步:常用的simulink库

打开以后会看到simulink library browser这个界面

最常用的就是simulink和他的子模块

点一下左上角小图标,会新建一个model

在block里选择一个图标,右键,add on……

1、file-model properties 模型属性

2、simulink preferences 全局特性窗口

<1>solver 设置求解器

开始时间、ode45

如何连接simulink:

正确连接就是黑色,连接失败就是虚线或者是红色的

基本操作—模块参数的设置、仿真器的设置、运行仿真:

正弦信号发生器:

幅值(amplitude)、相位(bias)、频率(frequency)、初始相位(phase)、采样时间(sample time)

仿真器的设置:

simulation-model configuration parameters

start time、stop time

type:variable-step(可变步长)

slover:ode45

设置好以后运行

增益器:

改变幅值

微分器(连续时间模块子集):

频率是几就扩大几倍

死区模块(非连续时间模块子集):

设置死区,某区间的输出是0

饱和模块(非连续时间模块子集):

设置饱和区,大于某数值是输出为1

间隔测试模块(非连续时间模块子集):

设置上限和下限

数位提取模块:

输入常数项28,数位提取模块提取需要的二进制位

复数模块:

第一个是实部,第二个是实部,然后把它变成复数,接下来把它变成复数的值和角度

回调函数: file-model properties-callbacks就可以看到他的所有回调函数,有程序的就是星号标注

MATLAB符号函数的图形绘制:

一元函数:

clear all;

x=-2:0.1:4;

figure

plot(x,humps(x));

title(‘plot’);

fugure;

fplot(@humps,[-2 4])%更加光滑

title(‘fplot’);

同时画三个曲线:

clear all;

figure;

fplot(’[1/x,sin(x),cos(x)]’,2pi[-1 1 -1 1]);%x,y都是-2pi到2pi

legend(‘1/x’,‘sin(x)’,‘cos(x)’);

极坐标绘图:

clear all;

figure;

ezpolar(‘sin(8 * t).* cos(8* t)’,[0,pi]);

符号函数的三维网格图:

clear all;

figure;

ezmesh(‘x.* exp(x.2-y.2)’);

带有等值线的三维网格图:

clear all;

figure;

ezmeshc(‘x.exp(-5x.2-8*y.2)’);

符号函数的等值线图:

clear all;

figure;

ezcontour(‘x.* exp(-x.2-y.2)’,[-3 3]);

三维彩色曲面图:

clear all;

figure;

ezsurf(‘x.* y.3/(x.2+y.^3)’);

带有等值线的三维彩色的曲面图:

clear all;

figure;

ezsurfc(‘4* x.* exp(-4* x.^2 - 6* y.^2)’);

MATLAB基本绘图函数:

clear all;

t=0.1:0.02:2* pi; %自变量范围

figure;

plot(t,sin(t),‘r:’); %红色

hold on;

plot(t,cos(t)); %绘制

xlabel(‘x’); %横坐标标签

ylabel(‘y’); %纵坐标标签

title(‘plot’); %题目

clear all;

y=magic(4); %%4行4列的矩阵

figure;

plot(y); %对每一列绘制一条线,那就是4条,每条4个点,默认颜色不同

clear all;

x=0:0.1:16;

y=sin(x);

figure;

plot(x,y);

clear all;

x=1:4;

y=magic(4);

figure;

plot(x,y);

clear all;

x=0.01:0.1:2pi;

y=cos(x+0.7)+5;

figure;

plot(x,y,'r-.’); %红色,线型

clear all;

x=0.01:0.2:6* pi;

y=cos(x);

figure;

plot(x,y,‘g:^’);

%%

clear all;

x=-pi:pi/20:pi;

y=tan(sin(x))-sin(tan(x));

plot(x,y,’–rs’,‘LineWidth’,1,…

‘MarkerEdgeColor’,‘k’,…

‘MarkerFaceColor’,‘g’,…

‘MarkerSize’,4);

同时绘制多条曲线:

clear all;

x=-pi:pi/20:pi;

y=sin(x);

z=cos(x);

figure;

plot(x,y,'r:* ',x,z,‘g-.v’);

MATLAB子图绘制和坐标轴控制:

clear all;

x=-pi:pi/20:pi;

figure;

subplot(2,1,1);

plot(x,sin(x),‘r–’);%红色

subplot(212);

plot(x,cos(x),'b:* ');%蓝色

clear all;

x=-pi:pi/20:pi;

figure;

subplot(2,2,1);

plot(x,sin(x),‘r–’);

subplot(223);

plot(x,cos(x),‘b:*’);

subplot(2,2,[2 4]);

plot(x,sin(x)+cos(x),‘b-.^’);

坐标轴的设置:

clear all;

t=0.01:0.01:pi;

figure;

plot(sin(t),cos(t));

axis %% 设置坐标轴 获取当前坐标轴

clear all;

t=0.01:0.01:pi;

figure;

plot(sin(t),cos(t));

axis([-1 1 -2 2]); % 设置坐标轴显示范围

clear all;

t=0.01:0.01:pi;

figure;

plot(sin(t),cos(t));

axis off %取消坐标轴的显示

matlab网格线和边框设置:

clear all;

t=0.01:0.01:2pi;

figure;

plot(t,sin(t));

axis([0 2pi -1 1]);

grid on; %显示网格线

clear all;

t=0.01:0.01:2pi;

figure;

plot(t,sin(t));

axis([0 2pi -1 1]);

box off; %关闭边框

坐标轴的缩放:

clear all;

t=0.01:0.01:2*pi;

figure;

subplot(121);

plot(t,sin(t));

axis([-5 10 -3 3]);

title(‘放大前’);

subplot(122);

plot(t,sin(t));

axis([-5 10 -3 3]);

zoom on;

title(‘放大后’);

clear all;

t=0.01:0.01:2* pi;

figure;

subplot(121);

plot(t,sin(t));

axis([-5 10 -3 3]);

title(‘放大前’);

subplot(122);

plot(t,sin(t));

axis([-5 10 -3 3]);

zoom xon;

title(‘x轴放大后’);

matlab绘图中级技巧:

图的拖拽:

clear all;

t=0.01:0.01:2* pi;

figure;

plot(t,sin(t),’–r’);

pan on;%打开拖拽功能

数据光标:

clear all;

t=0.01:0.01:2* pi;

figure;

plot(t,sin(t),’–r’);

datacursormode on;%获取数据点

绘制直线:

clear all;

x=0.1:0.8:2pi;

y=sin(x);

figure;

line(x,y);

极坐标绘图:

clear all;

x=0:0.02:2 pi;

y=sin(2* x).* cos(2* x);

figure;

polar(x,y,’–r’); %% 弧度 半径 线型

双Y轴绘图:

clear all;

x=0.1:0.1:2* pi;

y=sin(x);

z=10.^x;

figure;

plotyy(x,y,x,z);

图形的编辑操作:

clear all;

x=0.1:0.1:2pi;

y=cos(x);

figure;

plot(x,y);

axis([0,2pi,-1,1])

title(‘余弦函数’,‘fontname’,‘宋体’,‘fontsize’,10,‘fontweight’,‘bold’);

在生成的图形里点开编辑,可以找到“图形属性”

matlab坐标轴标题和图例:

坐标轴标题:

clear all;

x=0.1:0.1:2* pi;

y=sin(x);

figure;

plot(x,y);

axis([0,2* pi,-1,1])%横坐标0到2π,纵坐标-1到1

xlabel(’\it横轴标题’,‘fontname’,‘宋体’);

ylabel(‘纵轴标题’,‘fontname’,‘宋体’,‘rotation’,-90);%没有最后的90度,会变成横着的

图例:

clear all;

x=0.1:0.1:2* pi;

y=sin(x);

z=cos(x);

figure;

subplot(121);

plot(x,y,’-b’);

hold on;

plot(x,z,’–r’);

axis([0,2* pi,-1,1])

set(gca,‘XTick’,[0 pi 2* pi],‘XTickLabel’,{‘0’,‘pi’,‘2pi’});%

xtick是刻度(小竖线);xticklabel 刻度值(竖线下面的数值)。

set(gca,‘xtick’,-pi:pi/2:pi)这句的意思是:手动设置x轴刻度,-pi到pi之间,每间隔pi/2,划一小竖线。

set(gca,‘xticklabel’,{’-pi’,’-pi/2’,‘0’,‘pi/2’,‘pi’})这句的意思是:给刚才划上的小竖线,标个数值。如果你把它改成:set(gca,‘xticklabel’,{‘a’,‘b’,‘c’,‘d’,‘e’}),那么那小竖线下就变成:a,b,c,d,e了。

legend(‘sin(x)’,‘cos(x)’);

subplot(122);

plot(x,z,’:r’);

hold on;

plot(x,y,’-b’);

axis([0,2* pi,-1,1])

legend(‘cos(x)’,‘sin(x)’);

legend boxoff; %隐藏图例的边框,不隐藏边框就可以拖动,建议不要

文本框标注:

clear all;

x=0:0.1:2* pi;

y=sin(x);

figure;

plot(x,y,’–b’);%线性–颜色blue

xlabel(‘x’);

ylabel(‘sin(x)’);

text(pi,sin(pi),’\leftarrow sin(\pi)=0’);%在π,sin(π)处标注,箭头向左

text(0,0,’\leftarrow sin(0)=1’);

任意位置:

clear all;

x=0:0.1:2* pi;

y=sin(x);

figure;

plot(x,y,’–b’);

xlabel(‘x’);

ylabel(‘sin(x)’);

gtext(‘y=sin(x)’,‘fontsize’,10);%只能放一次

各类二维图的绘制:

饼状图:

clear all;

figure;

x=[0.2 0.3 0.2];%概率,不完整饼

subplot(121);%表示在本区域里显示1行2列个图像,最后的1表示本图像显示在第一个位置。

pie(x)

subplot(122);

y=[0.1 0.2 0.3 0.2 0.2];

explode=[0 0 1 0 0]; % 第三个突出

pie(y,explode);

绘制直方图:

clear all;

figure;

x=randn(500,1); %标准正态分布

subplot(121);

hist(x); %默认10个柱子

subplot(122);

y=randn(800,1);%800个标准正态分布的数据

hist(y,-4:0.1:4); %生成直方图,指定范围

散点图:

clear all;

figure;

x=[1 3 4 7 9 10 15];

y=[5 3 5 9 7 3 7];

subplot(121);

scatter(x,y);

subplot(122);

scatter(x,y,[],[1 0 0],‘fill’) %散点的颜色和填充

火柴杆图:

clear all;

x=0.1:0.5:5* pi;

y=sin(x);

figure;

stem(x,y,‘r’);

阶梯图:

clear all;

x=0.1:0.5:5* pi;

y=cos(x);

figure;

stairs(x,y,‘r’);

绘制罗盘图:

clear all;

x=[1 -3 5 -6 8 9];

y=[5 7 -9 12 15 -9];

figure;

compass(x,y,‘r’);%绘制罗盘图

羽毛图:

clear all;

x=[1 3 5 6 8 9];

y=[5 7 -9 3 -5 2];

figure;

feather(x,y);

彗星图(动态的):

clear all;

t=-pi:pi/100:pi;

y=tan(sin(t))-sin(tan(t));

comet(t,y);

三维图的绘制:

clear all;

x=-10:0.1:10; %绘图数据

y=-10:0.1:10;

[X,Y]=meshgrid(x,y);

z=X.2+Y.2;

figure; %图形窗口

surf(x,y,z); %三维图的绘制函数

view([55 75]) %设置视角

colormap(‘cool’); %设置颜色

shading interp;

light(‘Position’,[1 0.4 0.4]); %设置光照

axis square; %坐标轴设置

xlabel(‘x’); %图形标注

ylabel(‘y’);

zlabel(‘z’);

绘制三维曲线:

clear all;

t=linspace(0,20*pi, 500);

x=t. * sin(t);

y=t. * cos(t);

z=t;

figure;

plot3(x, y, z);

xlabel(‘x’);

ylabel(‘y’);

zlabel(‘z’);

绘制网格矩阵:

clear all;

x=-2 * pi:2 * pi;

y=-2 * pi:2 * pi;

[X,Y]=meshgrid(x,y);%产生矩形网格

figure;

plot(X,Y,‘o’);%绘制网格数据

绘制三维网格图:

clear all;

[X,Y]=meshgrid(-3:0.1:3);

Z=5 * X.2-Y.2+3;

figure;

subplot(121);

plot3(X,Y,Z);%绘制三维曲线图

subplot(122);

mesh(X,Y,Z);%绘制三维网格图

xlabel(‘x’);

ylabel(‘y’);

zlabel(‘z’);

绘制三维饼图:

clear all;

x=[0.2 0.1 0.25 0.15 0.16];

y=[3 5.5 7 10.5 8.5];

figure;

subplot(121);

pie3(x)%绘制三维饼图

subplot(122);

explode=[0 0 0 1 0];

pie3(y,explode);%绘制三维饼图

绘制三维散点图:

clear all;

x=rand(1,20);

y=rand(1,20);

z=x+y;

figure;

subplot(121);

scatter3(x,y,z)%绘制三维散点图

subplot(122);

scatter3(x,y,z,‘r’,‘filled’); %绘制三维散点图

绘制三维火柴杆图:

clear all;

x=rand(1,20);

y=rand(1,20);

z=x+y;

figure;

subplot(121);

stem3(x,y,z)%绘制三维火柴杆图

subplot(122);

stem3(x,y,z,‘r’,‘filled’); %绘制三维火柴杆图

绘制三维彗星图:

clear all;

t=-pi:pi/400:pi;

x=sin(5 * t);

y=cos(3 *t);

z=t;

figure(15);

comet3(x,y,z);%绘制三维彗星图17.36

点赞

收藏

分享

文章举报

4ec8e441b8ae67d8d48d54f0a08ebb55

d1358d4695d8660de2972cc1f6e682b2.png

JOE.BOX

发布了11 篇原创文章 · 获赞 6 · 访问量 317

私信

关注

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值