[Matlab] [Code] Overview

1, string

 A='MATLAB 7.0'

Here Insert Picture Description

whos

Here Insert Picture Description
2, input commands and statements

2*sin(0.3*pi)/(1+sqrt(5))

Here Insert Picture Description
3, the input matrix

 A=[1,2,3
      4,5,6
      7,8,9]

Here Insert Picture Description

4, statements with variables

(1)

1996/18

Here Insert Picture Description
(2)

s=1-1/2+1/3-1/4+1/5-1/6+...
   1/7+1/8;

Here Insert Picture Description

s

Here Insert Picture Description
5, the subscript of the matrix

x=4:6

Here Insert Picture Description

A=[x-3;x;x+3]

Here Insert Picture Description

C=A(1:2,2:3)

Here Insert Picture Description

A(2,2)=0

Here Insert Picture Description

A(:,1)=1

Here Insert Picture Description
6, have a special matrix

a=rand(5,5)

Here Insert Picture Description

a(:,1:3)=[]

Here Insert Picture Description
7, data input / output

(1)

xm=input('What''s your name:','s')

Here Insert Picture Description
(2)

A='Hello,MATLAB';
   disp(A)

Here Insert Picture Description
8, the input three sides of the triangle, required area of ​​the triangle.

A=input('请输入三角形的三条边:');
   if A(1)+A(2)>A(3)&A(1)+A(3)>A(2)&A(2)+A(3)>A(1)
      p=(A(1)+A(2)+A(3))/2;
      s=sqrt(p*(p-A(1))*(p-A(2))*(p-A(3)));
      disp(s);
  else
      disp('不能构成一个三角形。')
  end

[4 5 6]

Here Insert Picture Description
9, asked [100, 1000] within manner all prime numbers.

n=0;
   for m=100:1000
      flag=1;j=m-1;
      i=2;
      while i<j & flag
         if rem(m,i)==0
            flag=0;
         end
         i=i+1;
      end
      if flag
         n=n+1;
         prime(n)=m;
      end
    end
    disp(prime)

Here Insert Picture Description
10, MATLAB program analysis

function result = Exam13(Count)
for k = 1:Count
    result(k) = sin(k/50);
    if result(k)<-0.9
        result(k) = gammaln(k);
    end;
end;

Here Insert Picture Description

 profile on

Here Insert Picture Description

profile clear

Here Insert Picture Description

Exam13(50000);

Here Insert Picture Description

profile report

Here Insert Picture Description
11, an array of pre-allocated

x = 2

Here Insert Picture Description

x(3,5)=6

Here Insert Picture Description
Micro-channel public number "Fundamentals of Computer Science" concerned about my yo

Published 57 original articles · won praise 13 · views 3141

Guess you like

Origin blog.csdn.net/qq_41985559/article/details/103317853