matlab实用命令

实用命令

打点测时

在需要测量的开始部分标记: tic    
在需要测量的结束部分标记: toc
记录程序从tic到toc运行所花费的时间

Image 翻转

fliplr(x)  	//左右翻转
flipud(x)	//上下翻转
rot90(x)	//旋转九十度

find non-zero elem index

%tipycally method to find the non-zero elem index in 2D matrix.
indices = find(matrix);         %find non-zero elem by rows, return rank.
[I, J] = ind2sub(size(matrix), indices);    %convert rank to row and col index

read multifile in certain directory

%a typical method for reading data from multitxt and merge them together.
datapath = ''% datapath = 'data/tennis/';
filelist = dir([datapath '/*.jpg']);
imagelist = {filelist.name};
for i = 1:nImg
   ld = dlmread([datapath imagelist{i}(1:end-4) '.jpg.txt']);
   w_gt = [w_gt; ld'];
end

Write and read .txt file

读写矩阵
dlmwrite('xpreds_3d.txt',preds_3d);     //store preds_3d matrix, it can only store 2 demension matrix
M = dlmread('inputdata/o-ldmk.txt');
//if demension is more than 2 ,it will merge from second dimension
读写文本
fp = fopen(fileOut,'w');
fprintf(fp,'%d %d',m,n);
fclose(fp);
dlmwrite(fileOut,data1,'-append','delimiter',' ','roffset',1,'coffset',0);   //以空格结尾

save and load .mat

save(‘xx.mat’, ‘varname’)则变量varname会被保存在当前目录下xx.mat文件。
再要使用变量时只要用load(‘xx.mat’)变量会被读入。
如果使用xx = load(‘xx.mat’)读入,则xx.xx为真正的存入变量。

Repmat

A = [1 2; 3 4];
B = repmat(A, [2 3 2]);
//以A为子模块,把B复制成2行3列元素为A的大矩阵,并且这样的矩阵有两份

std2

std2(matrix) = sqrt( 1/(size(matrix,1)*size(matrix,2)) * sum( (mean(matrix(:)) - matrix ))(:) );
posted @ 2017-03-04 11:38  fariver  阅读(403)  评论(0编辑  收藏  举报