matlab基础操作(九)

51.离散杆图stem

例如,余弦波的采样信号图

>> t=linspace(-2*pi,2*pi,20);

>> h=stem(t,cos(t));

例如,分别以条形图、填充图、阶梯图和杆图形式绘图

>> subplot(221);

>> bar(x,y,'g');

>> title('bar(x,y,''g'')');

>> subplot(222);

>> fill(x,y,'r');

>> title('fill(x,y,''r'')');

>> subplot(223);

>> stairs(x,y,'b');

>> title('stairs(x,y,''b'')');

>> subplot(224);

>> stem(x,y,'k');

>> title('stem(x,y,''k'')');

52.极坐标图polar

polar函数用来绘制极坐标图,其调用格式为:polar(theta,rho,选项)

例如,绘制ρ=sin(2θ)

>> theta=0:0.01:2*pi;

>> rho=sin(2*theta);

>> polar(theta,rho,'k');

53.三维绘图的基本操作

三维线图指令plot3:三维绘图指令中,plot3最易于理解,它的使用格式与plot十分相似,只是对应第三位空间的参量。

>> t=(0:0.02:2)*pi;

>> x=sin(t);

>> y=cos(t);

>> z=cos(2*t);

>> plot3(x,y,z,'b-',x,y,z,'bd');

>> view([-82,58]);

>> box on

>> legend('链','宝石')

54.三维网线图(mesh)和曲面图(surf)

画函数z=f(x,y)所代表的三维空间曲面,需要做一下的数据准备工作:

确定自变量的取值范围和取值间隔。

x=x1:dx:x2;

y=y1:dy:y2;

构成x-y平面上的自变量采样"格点"矩阵。

利用MATLAB指令meshgrid产生"格点"矩阵;

[xa,ya]=meshgrid(x,y);

计算函数在自变量采样"格点"上的函数值,即z=f(x,y)。

网线图、曲面图绘制。

例如,绘制函数z=x^2+y^2的曲面

>> x=-4:4;

>> y=x;

>> [x,y]=meshgrid(x,y);%生成x-y坐标"格点"矩阵

>> z=x.^2+y.^2;%计算格点上的函数值

>> subplot(1,2,1),mesh(x,y,z);%三维网格图

>> subplot(1,2,2),surf(x,y,z);%三维曲面图

>> colormap(hot);

55.图像文件的读写与图像显示

imread指令-读取图像文件(BMP,GIF,PNG,JPEG,andTIFF)

imshow指令-显示图像

imwrite指令-保存图像

例如,读取图像文件

>> img1=imread('shenxianyeye.jpg');

>> img2=imread('cat.tif');

>> whos img1 img2

Name Size Bytes Class Attributes

img1 768x1024x3 2359296 uint8

img2 598x1005x3 1802970 uint8

>> imshow(img1);%显示图片

简单图像处理

>> lighter=2*img1;%改变图片的亮度

>> subplot(1,2,1);

>> imshow(img1);

>> title('Original');

>> subplot(1,2,2);

>> imshow(lighter);

>> title('Lighter');

>> imwrite(lighter,'mysaved.jpg');%保存图像

>> dir mysaved.*;%查看保存结果

mysaved.jpg

>> black=rgb2gray(img1);%彩色图像转换为灰度图像

>> imshow(black);

>> zoom on%图像的缩放

相关推荐
studyer_domi9 小时前
matlab质子磁力仪传感器线圈参数绘图
人工智能·matlab
青橘MATLAB学习14 小时前
模糊综合评价法:原理、步骤与MATLAB实现
开发语言·算法·数学建模·matlab·分类
studyer_domi14 小时前
matlab 三维时频图绘制
开发语言·matlab
studyer_domi18 小时前
matlab飞行姿态pid控制
matlab
Matlab仿真实验室18 小时前
基于Matlab实现信道估计仿真(源码)
开发语言·matlab·信道估计仿真
studyer_domi20 小时前
matlab 汽车abs的pid控制仿真
开发语言·matlab·汽车
studyer_domi20 小时前
matlab 汽车abs的模糊pid和pid控制仿真
开发语言·matlab·汽车
freexyn1 天前
Matlab自学笔记四十七:如何把日期时间型数据作为横坐标进行绘图
开发语言·笔记·matlab
见你背影1 天前
matlab数据处理:创建网络数据
matlab
chinakq2 天前
C++学习计划(三周) 有matlab和python基础,如何快速入门C++(利用《C++ primer plus》)
c++·学习·matlab