MATLAB作业
输入想x,y的值,将它们互换后输出。
1.3-3 大小写字 母转换 1.3-4Case的用法
1.3-5 1.3-6
输出水仙花数 求[100~200]之间第一个被21整除的数
1.3-7 1.3-8
将华氏温度转化为摄氏度 编写函数求半径为r的圆的周长和面积
1.3-10 1.3-11
无穷级数 生成一个5x10000的Hilbert长方矩阵,其中第i行第j列元素为h-{i,j}=1/(i+j-1)
n = 128; //把128赋值给n
u = linspace(0,pi,n); //产生n个步长为n/pi的矩阵
v = linspace(0,pi,n); //产生n个步长为n/pi的矩阵
u = repmat(u,n,1); // 将
y = sin(v).*sin(u); //将右边的值一一赋值给y并形成y矩阵
z = cos(u); // 将右边的值赋值给z并形成一个矩阵
f = 1/2*((2*x.^2-y.^2-z矩阵复制n行
v = repmat(v',1,n); //将矩阵复制n列
x = cos(v).*sin(u); //将右边的值一一赋值给x并形成一个矩阵
y = sin(v).*sin(u); //将右边的值一一赋值给y并形成y矩阵
z = cos(u); // 将右边的值赋值给z并形成一个矩阵
f = 1/2*((2*x.^2-y.^2-z.^2) + 2*y.*z.*(y.^2-z.^2) + ...
z.*x.*(x.^2-z.^2) + x.*y.*(y.^2-x.^2)) //;将右边的值经过函数运算后,一一赋值给f,形成矩阵
g = sqrt(3)/2 * ((y.^2-z.^2) + z.*x.*(z.^2-x.^2) + x.*y.*(y.^2-x.^2)) //;同上
h = (x+y+z).*((x+y+z).^3 + 4*(y-x).*(z-y).*(x-z)); //同上
Clf //清除原有的图形
s = surf(f,g,h/10,u, ...
'LineStyle','none', ...
'FaceLighting','gouraud', ...
'FaceColor','interp'); //制作三维空间立体图,线性设置为无,并采用高氏着色法着色
colormap jet; //colormap类型设置为jet
axis off; //axes的样式为off
daspect([1 1 1]); //长宽高之比设置为1
l1 = light; //将light的值赋值给l1
l2 = light; //同上
lightangle(l1,70,-40);//设置光源的方向
lightangle(l2,-30,80);//同上
view(-40,32); //设置二维视角
camzoom(1.5);//输出三维图形
Demo2
We start by creating a magic square and assigning it to the variable A.A = magic(3)
A =
8 1 6
3 5 7 //创建一个三维矩阵
4 9 2
Here's how to add 2 to each element of A.Note that MATLAB requires no special handling of matrix math.A+2
ans =
10 3 8
5 7 9 //每个元素的值都叫二
6 11 4
The apostrophe symbol denotes the complex conjugate transpose of a matrix.Here's how to take the transpose of A.A'
ans =
8 3 4
1 5 9 矩阵的倒置
6 7
The symbol * denotes multiplication of matrices.Let's create a new matrix B and multiply A by B.B = 2*ones(3)
A*B
B =
2 2 2
2 2 2 //计算矩阵A与B的成绩
2 2 2
ans =
30 30 30
30 30 30 A与B相乘
30 30 30
We can also multiply each element of A with its corresponding element of B by using the .* operator.A.*B
ans =
16 2 12
6 10 14 A与B点乘
We can also multiply each element of A with its corresponding element of B by using the .* operator.A.*B
ans =
16 2 12
6 10 14 A与B中的元素一一对应相乘
8 18 4
MATLAB has functions for nearly every type of common matrix calculation. For example, we can find the eigenvalues of A using the "eig" command.eig(A)
ans =
15.0000
4.8990
-4.8990
MATLAB第二次作业
1.什么事数字图像
在计算机上对图像进行处理,在其空间和亮度上进行数字化,即有一般的图像经过采样、量化离散得到的图像。
2.数字图像的特点
数字图像是离散化的,是不连续的,是能够被计算机处理的,这就与模拟图像区别开来。
3.像素分辨率
数字图像是由许许多多的小方格组成,所有的小方格数即为像素,分辨率的大小与像素有关,像素越高,分辨率越高。
4.观察一张照片的分辨率
5. 1MB的图片的分辨率
S=1MB=1*1024*1024*8b,所以,所求像素为e=s/8或者e=s/24。
6.几种常见的digital image类型。
1.二值图像:
一幅二值图像的二维矩阵仅由0、1两个值构成,“0”代表黑色,“1”代白色。由于每一像素(矩阵中每一元素)取值仅有0、1两种可能,所以计算机中二值图像的数据类型通常为1个二进制位。二值图像通常用于文字、线条图的扫描识别(OCR)和掩膜图像的存储。
(2) 灰度图像:
灰度图像矩阵元素的取值范围通常为[0,255]。因此其数据类型一般为8位无符号整数的(int8),这就是人们经常提到的256灰度图像。“0”表示纯黑色,“255”表示纯白色,中间的数字从小到大表示由黑到白的过渡色。在某些软件中,灰度图像也可以用双精度数据类型(double)表示,像素的值域为[0,1],0代表黑色,1代表白色,0到1之间的小数表示不同的灰度等级。二值图像可以看成是灰度图像的一个特例。
(3) 索引图像:
1.4-1显示一幅当前目录下.bmp文件
1.4-2显示一幅当前目录下的.bmp文件