1, string
A='MATLAB 7.0'
whos
2, input commands and statements
2*sin(0.3*pi)/(1+sqrt(5))
3, the input matrix
A=[1,2,3
4,5,6
7,8,9]
4, statements with variables
(1)
1996/18
(2)
s=1-1/2+1/3-1/4+1/5-1/6+...
1/7+1/8;
s
5, the subscript of the matrix
x=4:6
A=[x-3;x;x+3]
C=A(1:2,2:3)
A(2,2)=0
A(:,1)=1
6, have a special matrix
a=rand(5,5)
a(:,1:3)=[]
7, data input / output
(1)
xm=input('What''s your name:','s')
(2)
A='Hello,MATLAB';
disp(A)
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]
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)
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;
profile on
profile clear
Exam13(50000);
profile report
11, an array of pre-allocated
x = 2
x(3,5)=6
Micro-channel public number "Fundamentals of Computer Science" concerned about my yo