matlab常用api

交互式获取矩形区域的坐标

>> rect = getrect
                            % in current axes
>> rect = getrect(fig)
                            % in the current axes of
figure fig
>> rect = getrect(ax)
                            % in the axes specified by
the handle ax.

Use the mouse to click and drag the desired rectangle(用鼠标拖拽获得期望的矩形区域). rect is a four-element vector with the form [xmin ymin width height](返回值是四个元素构成的一个vector). To constrain the rectangle to be a square, use a shift- or right-click to begin the drag.(想要限制这个矩形为一个正方形,使用shift或者单击右键开始拖拽)

格式化字符串

str = sprintf(formatSpec,A1,...,An)
            % Format data into string

尤其注意其返回值是格式化好的字符串;

title(sprintf('psnr=%.4f', psnr))

矩阵

创建对角矩阵:

>> diag([1, 2, 3])
ans =

     1     0     0
     0     2     0
     0     0     3

>> magic(3)
ans =

     8     1     6
     3     5     7
     4     9     2

>> diag(magic(3))
ans =

     8
     5
     2

            % 所以diag将序列转化为对角矩阵
            % 将矩阵(无论对角与否)转换为由对角线元素组成的向量
            % diag()具有提取矩阵对角线元素的作用
            % 据此我们可轻易计算一个方阵的迹
            % 同样的用法可适用于numpy中的diag函数
>> sum(diag(magic(3)))
15

字符串及路径的拼接

[str1, str2, str3]
[str1 str2 str3]
                % 实现字符串的拼接
for i = 1:5,
    ['data_batch', num2str(i), '.mat'] 
end

data_batch1.mat
data_batch2.mat
data_batch3.mat
data_batch4.mat
data_batch5.mat

路径的拼接,使用fullfile(pathA, pathB),以/(路径分隔符),组合成新的完整的路径。

fopen

fid = fopen('./name.txt', 'rb')

uigetfile

[filename, pathname] = uigetfile('*.m', 'choose a m file')

imresize

I1 = imread('./1.png');
I2 = imread('./2.png');
I2 = imresize(I2, [size(I1, 1), size(I1, 2)]);
                    % imresize()的第二个参数位置不必考虑二维和三维的问题

你可能感兴趣的:(matlab常用api)