help 某个函数名
可以打开某函数的文本描述;但有时候可能更加需要的是直接看它的实例文档,这时用doc 某个函数名
会更好。
如果你加以思考的话,这些小技巧都是可以通过help
来学习,比如你直接在matlab命令行输入help help
就可以看到help
的帮助文档,进而不断深入,像一棵树一样生长。
Matlab的基本数据结构:
1.cell
:
help cell
:
cell(N) is an N-by-N cell array of empty matrices.
cell(M,N) or cell([M,N]) is an M-by-N cell array of empty
matrices.
cell(M,N,P,...) or cell([M N P ...]) is an M-by-N-by-P-by-...
cell array of empty matrices.
cell(SIZE(A)) is a cell array the same size as A containing
all empty matrices.
2.who
命令返回告诉你workspaces里有哪些变量;whos
命令则返回这些变量更加详细的信息,比如size,class以及bytes。
Matlab简单绘图:
x = logspace(-1,2);
y = exp(x);
loglog(x,y,'-s')
grid on
pie([2 4 3 5],{'North','South','East','West'})
:
X = linspace(0,4*pi,40);
Y = sin(X);
figure
stairs(Y)
Matlab函数的定义:
function [out_1,out_2] = flower(a,b,c)
20190318
20190416 使用matlab的imtool
函数直观地看下数字图像的pixel。
imtool('this.jpg')
使用immultiply
函数增加图片的亮度:
20190514
Matlab定位函数和文件的方法:使用which
函数。
比如查找Matlab的文件路径设置配置文件所在的位置就可以用:
which pathdef.m
找到。
20190518
SPM常用的一些函数:
- Loading and reading files
1.spm_vol
获取图像的头信息
V = spm_vol(P);
Get header information for images
FORMAT V = spm_vol(P)
P - a char or cell array of filenames
V - a structure array containing image volume information
The elements of the structures are:
V.fname - the filename of the image.
V.dim - the x, y and z dimensions of the volume
V.dt - A 1x2 array. First element is datatype (see spm_type).
The second is 1 or 0 depending on the endian-ness.
V.mat - a 4x4 affine transformation matrix mapping from
voxel coordinates to real world coordinates.
V.pinfo - plane info for each plane of the volume.
V.pinfo(1,:) - scale for each plane
V.pinfo(2,:) - offset for each plane
The true voxel intensities of the jth image are given
by: val*V.pinfo(1,j) + V.pinfo(2,j)
V.pinfo(3,:) - offset into image (in bytes).
If the size of pinfo is 3x1, then the volume is assumed
to be contiguous and each plane has the same scalefactor
and offset.
2.spm_read
读取完整的图像volumes
Images = spm_read_vols(V);
Read in entire image volumes
FORMAT [Y,XYZ] = spm_read_vols(V,mask)
V - vector of mapped image volumes to read in (from spm_vol)
mask - implicit zero mask?
Y - 4D matrix of image data, fourth dimension indexes images
XYZ - 3xn matrix of XYZ locations returned (in mm)
For image data types without a representation of NaN (see spm_type),
implicit zero masking can be used. If mask is set, then zeros are
treated as masked, and returned as NaN.
- Get data
spm_get_data
[Y] = spm_get_data(V,XYZ);
Get data from image files at specified locations
FORMAT [Y] = spm_get_data(V,XYZ,check)
V - [1 x n] struct array of file handles (or filename matrix)
XYZ - [3 x m] or [4 x m] location matrix (voxel)
check - check validity of input parameters [default: true]
Y - (n x m) double values
- Move between spaces
coordinate_in_mm = V.mat(1:3,:)*[C;1];
Inv = inv(V.mat);
coordinate_in_voxel = Inv(1:3,:)*[coordinate_in_mm ;1];
- Write images
V = spm_create_vol(V,varargin)
spm_write_vol(Info_img,matrix_to_write);
参考链接:http://www.sbirc.ed.ac.uk/cyril/SPM-course/Talks/2013/spm_programming.pdf