Machine-learning Course Study Summary Octave

Source: Internet
Author: User
Tags cos save file sin sprintf

Quick reference: Http://10.236.6.14/enacit1.epfl.ch/octave_doc/refcard/refcard-a4.pdf

1. Arithmetic operations:

A+b, A-A, a*b, A/b, a^b

Logical Operation:

A==b, a~=b (Not equal), A&&b, a| | B, Xor (A/b)

2. Assignment statement:

A=3;

A= ' Hi ';

A= 1>=3;

3. Output display:

A=pi

Disp (a)

Disp (sprintf (' 2 decimals:%0.2f ', a))

Disp (sprintf (' 6 decimals:%0.6f ', a))

Format Long

Format short

4. Vectors and matrices:

A=[1 2;3 4;5 6]

A=[1 2 3]

A=[1:0.1:2] %1-2 constructs a row vector in 0.1 units

A=1:6 %1-6 Line Vector

A=ones (3,4) % 3 Rows 4 columns Each element is 1 matrix

A=zeros (1,3) % 1 Rows 3 columns Each element is 0 matrix

A=randn (1,3) % normal distribution

A=7+SQRT (+) * (RANDN (1,10000)) % mean is 7, variance is square root

hist (A) % with 10bins column chart

hist (a,50) % with 50bins column chart

A=eye (5) % of the unit matrix with a order of 5

5. Data processing:

Load Abc.dat % Read File

who% lists variables in the working space

Whos % list details of variables in the workspace

Clear ABC % empty file

V=ABC (1:10) % read the first 10 data of the file

Save File.mat v; % save V to file

Save File.txt V-ascii; % save V to file in ASCII code

Size (A) % returns two values of the [Number of row series] vectors

Size (a,1) % number of rows

Size (a,2) % number of columns

Length (A) % maximum dimensions

A (:) %a all elements into a single column vector

A (3,2) % gets 3 rows of 2 columns of elements

A (2,:) % get line vector of line 2nd

A (2,:) =[2 3 4] % assigns A value to the 2nd row element

A=[A,[1;2;3]] % adds a column vector to the left of a

A ([1 3],:) % get all elements of a 1-3 line

C=[a B] % splicing matrix

C=[A,B]

C=[a; B

6. Data operation:

Set a=3*2 matrix, b=3*2 matrix, c=2*1 matrix

A*c

A.*b

A.^2

1./a

Log (A)

Exp (A)

ABS (A)

-A

A+1

A

Max (a) % returns a row vector with each value being the largest of each column, and if a is a row vector, only the maximum value is returned

Prod (A) % Ibid, just product

SUM (A) % Ibid, just and

SUM (a,1) % ibid .

SUM (a,2) % Ibid, return column vector

A<3 % Returns a homogeneous matrix, the value of <3 is 0 and vice versa is 1

Find (a<3) % returns the element position less than 3, which is a column vector

[R,c]=find (a<3) %ri,ci to conform to element coordinates

Flipud (A) % row reversal

PINV (a) inverse matrix of%a

7. Drawing

T=[0:0.01:0.98]

Y1=sin (2*pi*t)

Plot (t,y1) % drawing

On

Y2=cos (2*pi*t)

Plot (T,y2, ' R ')

Xlabel (' time ')

Ylabel (' value ')

Legend (' Sin ', ' cos ') % legend

Title (' My Plot ')

Print-dpng ' myplot.png ' % saved as picture file

Close % Closes the current diagram

Figure (1) % Create a diagram

CLF % Empty chart Current Contents

Subplot (1,2,2) % graph cut to 1*2 grid, draw 2nd grid

Axis ([0.5 1-1 1]) % axis changed to x belongs to [0.5,1],y belonging to [ -1,1]

Imagesc (The Magic ()), Colorbar,colormap Gray;

8. Loop condition Statements

For I=1:10,

V (i) =2^i;

End

------------------

While I<=5,

V (i) = 100;

i=i+1;

End

-------------------

If

ElseIf

Else

End

9. Functions:

function Y=fun (x)

y=x+2;

function [Y1,y2]=fun2 (x)

Y1=x*x;

Y2=x+x;

Called when the CD-to-function directory is then called directly

Ans=fun (args)

[A,b]=fun2 (args)

Machine-learning Course Study Summary Octave

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.