matlab 編程備忘

來源:互聯網
上載者:User

關於Sort的用法

  B=sort(A,dim) %沿著矩陣A中指定維數dim方向重新排列A中的元素。

  [B,IX]=sort(A); %其中IX是一個大小等於size(A)的數組,其每一列是A中列向量的元素相對應的置換位置記號。

matlab中結構變數的定義:

  在matlab定義基於結構的變數,直接對變數聲明為model=struct;即可運用。

matlab時間間隔的擷取:

  t = cputime; surf(peaks(40)); e = cputime-t

        e =
                      0.4667

matlab中擷取檔案的大小:

  %only for one file
  D = dir('C:\MATLAB6p5p1\work\example.mat');
  sizeoffile=D.bytes

  %or u can get all mat files size's in a directory
  D = dir('C:\MATLAB6p5p1\work\*.mat');
  sizeoffile=D.bytes
 
  D是一個struct,成員有name,date,bytes,isdir

matlab save 函數使用

  save data.mat

  for i=1: time_seg
      in(:,1)=up(:,i);
      in(:,2)=ul(:,i);
      in(:,3)=ut(:,i);
      tstr = ['t', int2str(i),'=in'];
      eval(tstr);
      save ( ['pjm_0102_t.mat'], ['t' num2str(i)], '-append');
  end

隨機排列函數

  randperm(n),產生一個1~n的隨機排列

按座標替換元素

  a=floor(lchrom*rand(1))+1;
      b=floor(lchrom*rand(1))+1;
      minmutation=max(a,b);
      maxmutation=min(a,b);
      p([minmutation  maxmutation])=p([maxmutation   minmutation]);

在二維座標畫點和線

  xy=rand(lchrom,2)*100

  for i=1:lchrom
      plot(xy(i,1),xy(i,2),'r*');
      hold on
  end

  ...

  draw(shortpath,xy);        %shortpath為指定座標點順序的向量

  

強制終止matlab運行

  啟用command window,然後按ctrl+c

matlab中的sleep

  pause(n),n為秒數,可以為小數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.