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
點贊
收藏
分享
文章舉報
JOE.BOX
發布了11 篇原創文章 · 獲贊 6 · 訪問量 317
私信
關注
總結
以上是生活随笔為你收集整理的matlab 绘制符号函数,DAY8 MATLAB学习笔记—simulink入门、MATLAB符号函数的图形绘制...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 批发电脑配件_2019年10月电脑配件表
- 下一篇: mysql主备切换 自动_核电生产管理信