Comparison of small function and r in MATLAB

Source: Internet
Author: User

Http://www.cnblogs.com/wentingtu/archive/2012/03/30/2425582.htmlR function more Complete blog

Seeking redundancy

y = 5;  x = 2; y%%x = 1;

MATLAB mod (y,x);

R y%%x;

Number of rows to fetch

Matlab size (m,1);

R Nrow (m);

Repeating matrix

1 2 3->1 2 3 1 2 3

Matlab Repmat (m,i,j) repeats I times by row, repeating J times by column. Use Repmat (m,1,2) as above

If you want to reach 1 2 3

1 2 3 effect with Repmat (m,2,1)

R Rep (m,2) repeats by column

Merging matrices

M1= 1 2 3 m2=4 5 6 m=1 2 3 4 5 6

Horizontal Merge

R Cbind (M1,M2);

matlab [M1,M2];

Merge vertically

R Rbind (M1, M2)

MATLAB [M1 m2];

No back-up random sampling

m, for the whole. Num is the number of samples to extract

Matlab randsample (m,num); Returns a k-by-1 vector y of values sampled uniformly at random, without replacement, from the Integers 1 to n.

R sample (M,num,replace=false); False means not to put back the sample, true to put back the sample

Creating a special matrix

R Mat.or.vec (i, J) I row J column all 0 matrices

MATLAB Zeros (I,J)

SSE = Matrix (data, I, J,byrow = TRUE) I row J column, where the data is data, arranged by rows

Find vector length

v = 1 2 3

R Length (v) =3

Matlab Length (v) =3

Multiply matrix corresponding elements

M1=1 2 3 m2= 4 5 6 m = 4 10 18

Matlab m1.*m2;

R m1*m2;

Normal multiplication of matrices

Matlab m1*m2

R m1%*%m2

Find standard deviation of sample

R SD (v)

MATLAB STD (v)

Find the lowest value subscript (usually take a vector, and then ask)

x = 5 2 1 4 10

R which.min (x) = 3

MATLAB find (x = = min (x))

Find the subscript where the specified element is located and reject

index= find (Matrix = = num) index holds the subscript for NUM, subscript is computed by column, and the second column is counted after one column

index = (vector > num) is larger than Num's subscript takes 1, the other takes 0, which is generally picked out and then used for culling

Vector (index) = []; exclude the element where index is located

Remove vector Specifies the value of the underlying

x = 5 8 10 11 12

R X[-1] = 8 10 11 12

Matlab x (1) =[]

Take the nearest number from 0

x = 1.7 y=-1.7

R As.integer (x) 1 As.integer (y) =-1

fix for MATLAB (x) fix (y)

Comparison of small function and r in MATLAB

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.