matlab 常用函数

1. int2str
Convert integer to string
Syntax

str = int2str(N)

2.  griddata

Interpolate scattered data
Syntax

vq = griddata(x,y,v,xq,yq)
vq = griddata(x,y,z,v,xq,yq,zq)
vq = griddata(..., method)
Examples

Interpolate Scattered Data Over a Uniform Grid

Sample a function at 100 random points between -2.0 and 2.0.
rng(0,'twister')
x = rand(100,1)*4-2; 
y = rand(100,1)*4-2;
z = x.*exp(-x.^2-y.^2);
x, y, and z are now vectors containing nonuniformly sampled data. Define a regular grid and interpolate the scattered data over the grid.
ti = -2:.25:2;
[xq,yq] = meshgrid(ti,ti);
zq = griddata(x,y,z,xq,yq);
Plot the gridded data along with the scattered data.
mesh(xq,yq,zq), hold
plot3(x,y,z,'o'), hold off
set(gca,'XTick',[-2 -1 0 1 2]);
set(gca,'YTick',[-2 -1 0 1 2]);

 3. interp2
2-D data interpolation (table lookup)

Example 1
Interpolate the peaks function over a finer grid.
[X,Y] = meshgrid(-3:.25:3);
Z = peaks(X,Y);
[XI,YI] = meshgrid(-3:.125:3);
ZI = interp2(X,Y,Z,XI,YI);
mesh(X,Y,Z), hold, mesh(XI,YI,ZI+15)
hold off
axis([-3 3 -3 3 -5 20])

4. gradient


Examples


The statements
v = -2:0.2:2;
[x,y] = meshgrid(v);
z = x .* exp(-x.^2 - y.^2);
[px,py] = gradient(z,.2,.2);
contour(v,v,z), hold on, quiver(v,v,px,py), hold off


 

5. imwrite

函数功能:将图像数据写入到图像文件中, 存储在磁盘上。在matlab命令窗口中键入doc imwrite或help imwrite可以获得更多关于该函数的帮助信息。

  调用格式:

  imwrite(A,filename,fmt)

  A是图像数据, filename是目标图像名字, fmt是要生成的图片的格式。图像格式有:bmp(1-bit、8-bit和24-bit)、gif(8-bit)、hdf、jpg(或jpeg)(8-bit、12-bit和16-bit)、jp2或jpx、pbm、pcx(8-bit)、pgm、png、pnm、ppm、ras、tif(或tiff)、xwd。各种格式支持的图像位数不一样,比如bmp格式不支持16-bit,而png格式支持, 又如gif只支持8-bit格式。

  imwrite(X,map,filename,fmt)

  如果要存储一张索引图像, 需要指定颜色表,这样在硬盘上生成图像文件时指定的颜色表和图像数据将一起写入图像文件。

  imwrite(...,filename)

  imwrite(...,Param1,Val1,Param2,Val2...)

 

程序示例

close all; clear; clc;

  warning off all;

  % 本例子展示如何将一张真彩色jpg格式图片转换为灰度图像、索引图像、二值图像

  imgrgb = imread('flower.jpg');

  imwrite(imgrgb, 'flower.bmp', 'bmp'); % jpg格式转换为bmp格式

  imggray = rgb2gray(imgrgb);

  imwrite(imggray, 'flower_grayscale.bmp', 'bmp'); % 存储为灰度图像

  [imgind, map] = rgb2ind(imgrgb, 256); % 转换为256色的索引图像

  % 如果转换为65536色图像, imwrite函数无法写入到文件, 这是因为: 65536色的

  % 索引图像数据类型是uint16(16-bit), 而imwrite函数的bmp文件格式仅仅支持

  % 1-bit, 8-bit, 和 24-bit。png格式支持uint16。

  imwrite(imgind, map, 'flower_index.bmp', 'bmp');

  imgbw = im2bw(imgrgb, 0.5);

  imwrite(imgbw, 'flower_binary.bmp', 'bmp');

6 . mat2gray


Convert matrix to grayscale image
Syntax

 

I = mat2gray(A, [amin amax])
I = mat2gray(A)


Examples

I = imread('rice.png');
J = filter2(fspecial('sobel'),I);
K = mat2gray(J);
imshow(I), figure, imshow(K)

7.


intmax


Largest value of specified integer type

 


Examples


Find the maximum value for a 64-bit signed integer:
v = intmax('int64')
v =
  9223372036854775807


Convert this value to a 32-bit signed integer:
x = int32(v)
x =
  2147483647


Compare the result with the default value returned by intmax:
isequal(x, intmax)
ans =
     1

8.


cumsum


Cumulative sum
Syntax

 

B = cumsum(A)
B = cumsum(A,dim)


Examples

cumsum(1:5)
ans =
       [1  3  6  10  15]

A = [1 2 3; 4 5 6];

cumsum(A,1)
ans =
       1     2     3
       5     7     9

cumsum(A,2)
ans =
       1     3     6
       4     9    15

 

9.


numel


Number of elements in array or subscripted array expression

) =
    16     5     9     4
     2    11     7    14
     3    10     6    15
    13     8    12     1

numel(a)
ans =
    32

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值