Matlab programming memo

Source: Internet
Author: User

Sort usage:

B = sort (A, dim) % rearrange the elements in a along the dim direction specified in matrix.

[B, IX] = sort (a); % Where IX is an array of sizes equal to size (, each column is the replacement position mark corresponding to the element of the column vector in column.

Definition of structural variables in MATLAB:

Define structure-based variables in MATLAB and declare them as model = struct.

MATLAB time interval acquisition:

T = cputime; SURF (peaks (40); E = cputime-T

E =
0.4667

Obtain the file size in MATLAB:

% Only for one file
D = Dir ('C: \ MATLAB 6p5p1 \ work \ example. Mat ');
Sizeoffile = D. bytes

% Or u can get all mat files size's in a directory
D = Dir ('C: \ MATLAB 6p5p1 \ work \ *. Mat ');
Sizeoffile = D. bytes
 
D is a struct with the name, date, bytes, and isdir members.

Matlab save Function usage

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

Random permutation Function

Randperm (n) generates a 1 ~ Random arrangement of N

Replace elements by coordinates

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]);

Draw points and lines in two-dimensional coordinates

XY = rand (lchrom, 2) * 100

For I = 1: lchrom
Plot (XY (I, 1), XY (I, 2), 'r *');
Hold on
End

...

Draw (coordinate path, XY); % coordinate path is the vector of the specified coordinate point sequence.

Force terminate MATLAB operation

Activate command window and press Ctrl + c

Sleep in MATLAB

Pause (N), n is the number of seconds, which can be decimal places

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.