matlab笔记

来源:互联网 发布:魔域副本源码 编辑:程序博客网 时间:2024/05/17 00:15

有些地方总是和python搞混 特此记下来

matlab a:b 生成array左右都是闭区间
array access用(), 且从1开始, 不是0

  • array dimension
size(array)%第一维的长度size(array,1)
  • cat
C = cat(dim, A, B)C = cat(dim, A1, A2, A3, A4, ...)
  • for
x = ones(1,10);# n = [2,6]for n = 2:6    x(n) = 2 * x(n - 1);end
  • print
fprintf('We all know %d+%d=%d!\n',1,1,2);
  • permute
im = permute(im, [2,1,3]); 
  • write float array to file
% 按照 row, column, channel 存储parr=permute(OUT_ARRAY,[3,2,1]);%sn=prod(size(parr));%rpa=reshape(parr,[1,prod(size(parr))]);fname='/path/to/out/out.bin';fileID = fopen(fname,'w');fwrite(fileID,parr,'float');fclose(fileID);
  • read float array
fname='/path/to/out/out.bin';fileID = fopen(fname,'r');SN=rows*cols*cn;data=fread(fileID,[1,SN],'float');fclose(fileID);%rdata=reshape(data,[rows,cols,cn]);rdata=reshape(data,[cn,cols,rows]);feat_2=permute(rdata2,[3,2,1]);
  • pause
pausepause(n)pause on pause off

pause by itself, causes M-files to stop and wait for you to press any key before continuing.
pause(n) pauses execution for n seconds before continuing.
pause on allows subsequent pause commands to pause execution.
pause off ensures that any subsequent pause or pause(n) statements do not pause execution. This allows normally interactive scripts to run unattended.

原创粉丝点击