0%

Matlab/Test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
% Test 1
% (1)生成一个空矩阵A
A = []
% 对A进行赋值,取值为5行5列的单位矩阵
A = eye(5)
% 将矩阵A存储在硬盘上的Matlab数据文件A.mat中
save A.mat A

%(2) 利用函数xlsread读取硬盘上电子表格
% data.xls中的第一个工作表区域中
% A2:C5的区域的数据(自行敲入),并赋值给矩阵
% B,然后利用命令保存矩阵B到硬盘上的B.mat文件中。

B =xlsread('data1.xlsx', 1, 'A2:C5')
save B.mat B

% (3) 利用load实现将数据文件A.mat 和 B.mat
% 载入到内存中,然后将A、B两个变量保存到MATLAB数据文件AB.mat中
load A.mat
load B.mat
save AB.mat A B
  • Test 3

    • 将大些字母转换为小写的两种方法
      1
      2
      3
      4
      5
      6
      7
      8
      9
      % 创建由数值和大小写字母构成的字符
      str = 'gfAFHSKFHsag354346'
      % 将大写字母转换为小写字母
      str = lower(str) % first

      % second
      % upper = find(str >='A' & str <= 'Z');
      % str(upper) = str(upper) + 32;
      % new = char(str)
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      % 创建由数值和大小写字母构成的字符
      str = 'gfAFHSKFHsag354346'
      % 将大写字母转换为小写字母
      str = lower(str)

      upper = find(str >='0' & str <= '9');
      str(upper) = 0;
      str = char(str);
      % 去掉尾部的空格
      str = deblank(str)

      % 在str的前面添加'New strings: '形成一个新的字符串
      add = 'New strings: ';
      newStr = ([add, str])
      % 统计字符串的字符数
      strSize = size(newStr)
  • Test 4

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    % 1 结构数组
    course=struct('courseName',{'Matlab程序设计','Java程序设计','线性代数','高等数学','大学物理'},'score',{2,2,2,2,2},'degreeOfDifficulty',{'difficult','difficult','difficult','medium','difficult'})
    % 新添教师姓名
    course(1).teacherName = '肖老师';
    course(2).teacherName = '龙老师';
    course(3).teacherName = '全老师';
    course(4).teacherName = '宋老师';
    course(5).teacherName = '王老师';
    % 显示course
    course
    % 删除难易信息
    course(1).degreeOfDifficulty = [];
    course(2).degreeOfDifficulty = [];
    course(3).degreeOfDifficulty = [];
    course(4).degreeOfDifficulty = [];
    course(5).degreeOfDifficulty = [];
    % 显示course
    course

    % 2 创建元胞数组

    course=cell(6,3);
    % 设置第一栏
    course(1,1)={'courseName'};
    course(1,2)={'score'};
    course(1,3)={'degreeOfDifficulty'};

    % 填写courseName信息
    course(2,1)={'Matlab程序设计'};
    course(3,1)={'Java程序设计'};
    course(4,1)={'线性代数'};
    course(5,1)={'高等数学'};
    course(6,1)={'大学物理'};

    % 填写score信息
    course(2,2)={2};
    course(3,2)={2};
    course(4,2)={2};
    course(5,2)={2};
    course(6,2)={2};

    % 填写degreeOfDifficulty信息
    course(2,3)={'difficult'};
    course(3,3)={'difficult'};
    course(4,3)={'difficult'};
    course(5,3)={'medium'};
    course(6,3)={'difficult'};

    % 添加第四个信息教师姓名
    course(1,4)={'teacherName'};
    course(2,4) = {'肖老师'};
    course(3,4)={'龙老师'};
    course(4,4)={'全老师'};
    course(5,4)={'宋老师'};
    course(6,4)={'王老师'};

    % 删除难易程度信息
    course(1,3)={[]};
    course(2,3)={[]};
    course(3,3)={[]};
    course(4,3)={[]};
    course(5,3)={[]};
    course(6,3)={[]};

    % 显示course
    course
  • Test 5

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    % 创建系数矩阵
    numbers=[1 -1 1;2 1 1;1 -1 -2];

    % 行列式
    A=det(numbers)

    % 迹
    B=trace(numbers)

    % 秩
    C=rank(numbers)

    % 逆
    D=inv(numbers)

    % 求解方程组
    b=[1 2 4];
    x=inv(A)*b
  • Test 6

    1
    2
    3
    4
    5
    6
    % Test 6
    A = [-10000:10000];
    num=find(A>1000 & mod(A,17)==0);
    Size=size(A(num))
    All=A(num);
    B=All(end-9:end)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
% 简答与编程三 数据可视化
% Test 1
% 分别绘图
% sin(x)
x1=linspace(0,4*pi,2000);
plot(x1,sin(x1))

% cos(x)
x2=linspace(-pi,3*pi,2000);
plot(x2,cos(x2))

% tan(x)
x3=linspace(0,4*pi,2000);
plot(x3,tan(x3))

% 绘制在一幅图中
subplot(131);
plot(x1,sin(x1))
subplot(132);
plot(x2,cos(x2))
subplot(133);
plot(x3,tan(x3))



% Test 2
% sin(x)
x1=linspace(0,4*pi,2000);
plot(x1,sin(x1),'k')
axis auto;
hold on;

% cos(x)
x2=linspace(-pi,3*pi,2000);
plot(x2,cos(x2),'--g*','linewidth',3)
hold on;

% tan(x)
x3=linspace(0,4*pi,2000);
plot(x3,tan(x3),'-.ro','linewidth',2);

% 图例标注
legend('sin(x)','cos(x)','tan(x)','4');

% Test3
x=linspace(-3,3,49);
y=linspace(-3,3,49);
[xx,yy]=meshgrid(x,y); %确定作图的范围
zz=xx.^2/8-yy.^2/3;

% 使用mesh函数
mesh(xx,yy,zz)

% 使用surf函数
surf(xx,yy,zz)


% Test4

% sin(x)
x1=linspace(0,4*pi,2000);
p1=plot(x1,sin(x1));
hold on;
% cos(x)
x2=linspace(-pi,3*pi,2000);
p2=plot(x2,cos(x2));

% 获取图形句柄并修改曲线属性
h1=findobj(p1);
set(h1,'color','r')
set(h1,'linewidth',2)
h2=findobj(p2);
set(h2,'color','g','linestyle','--')

% 简答与编程五 程序设计
% Test 01
% swith
score1 = input('Please enter your score1:');
switch score1
case num2cell(90:100)
disp('A')
case num2cell(80:89)
disp('B')
case num2cell(70:79)
disp('C')
case num2cell(60:69)
disp('D')
case num2cell(0:59)
disp('E')
otherwise
error('Inputting Error!')
end


% if
score2 = input('Please enter your score2:');
if (score2 >= 90 & score2 <= 100)
disp('A')
elseif (score2 >= 80 & score2 <= 89)
disp('B')
elseif (score2 >= 70 & score2 <= 79)
disp('C')
elseif (score2 >= 60 & score2 <= 69)
disp('D')
elseif (score2 >= 0 & score2 <= 59)
disp('E')
else
error('Inputting Error!')
end

% Test 02
% 数值计算:计算出0-1000之间所有是4的倍数的整数的和
% for循环
s1=0;
for i = 0:4:1000
s1=s1+i;

end
s1

% while 循环
num=0;
s2=0;
while num<=1000
s2=s2+num;
num=num+4;
end
s2
% 不使用循环语句
s3=sum(0:4:1000)
% 显然s1,s2,s3的值都是相等的

% 符号计算
% 计算出 1+1/2^2+1/3^2+...+1/k^2+...的前10项和

% for 循环
s4=0;
for j = 1:10
s4=s4+1/j^2;
end
s4
% while 循环
s5 = 0;
num1=1;
while num1<=10
s5=s5+1/num1^2;
num1=num1+1;
end
s5
% 不使用循环语句
syms k
s6=symsum(1/k^2,1,10)

% Test 02'!!!!
% for 循环
s1= 0;
for i = 0:10000001;
s1=s1+0.2^i;

end
s1

% while循环
num=0;
s2=0;
while num<=1000000
s2=s2+0.2^num;
num=num+1;
end
s2

% 很显然s1和s2是相等的。

% Test 03
function [] = Test(varargin)
% Test 给定不同的输入绘画出不同的图形
% 当没有输入量时,画出单位圆
% 当输入量是大于2的整数N时,绘制正N边形并在图片名中反映显示多边形的真实边数
% 当输入量是"非自然数数"时,给出"出错提示"。
% Author:雷博闻
% Time: 2020/03/25
if nargin == 0
angle=0:pi/360:2*pi;
figure(1);
plot(1*sin(angle),1*cos(angle));
axis tight
axis equal

elseif nargin ==1
a = varargin{1};
if a > 2 & rem(a,1)==0
pgon=nsidedpoly(a);
figure(1);
plot(pgon)
title(['正',num2str(a),'边形'])
axis equal
axis tight

elseif a<0 | (a>=0 & rem(a,1)~=0)
error('请输入一个自然数!')
else
error('超出范围')
end

end

% Test 04
n=[2:100];
number=0;
tem=0;
sum=0;
for i=1:length(n)-1
tem=n(i)*n(i+1)-1;
for j=2:floor(tem/2)
if rem(tem,j)~=0
if j==floor(tem/2)
disp([num2str(n(i)),'和',num2str(n(i + 1)),'是一对亲密数'])
number=number+1;
sum=sum+tem;
end
else
break;
end
end
end

number
sum

% 简答与编程5 数值计算
% Test1
function [] =Test
A = [27 6 -1;6 15 2;1 1 54];
b = [85;5;110];

% LU 分解法
[L,U] = lu(A);
X = U\(L\b)

% 雅可比迭代法
[x1,n1]=jacobi(A,b, [0;0;0],1.0e-3)

% G-S迭代法
[x2,n2]=gauseidel(A,b, [0;0;0],1.0e-3)

function [y,n] = jacobi(A,b,x0,ep)
% 雅可比迭代法算法
D = diag(diag(A));
L = -tril(A,-1);
U=-triu(A,1);
B=D\(L+U);
f=D\b;
y=B*x0+f;
n=1;
while norm(y-x0) >= ep
x0=y;
y=B*x0+f;
n=n+1;
end

function [y,n]=gauseidel(A,b,x0,ep)
D = diag(diag(A));
L = -tril(A,-1);
U=-triu(A,1);
B=(D-L)\U;
f=(D-L)\b;
y=B*x0+f;
n=1;
while norm(y-x0) >= ep
x0=y;
y=B*x0+f;
n=n+1;
end

% Test 2


function [] = Test()
% 主函数
% solve 命令求解
syms x
answer=solve(x.^3 - 3*x+1);
vpa(answer)

% 实现逐步搜索法求方程的解
tic
X=StepSearch(-10,10,0.001,0.0001)
toc
% 实现二分法
tic
[k1,x1,wuca1,yx1]=erfen(-2,-1,0.0001);
x1
[k2,x2,wuca2,yx2]=erfen(0,1,0.0001);
x2
[k3,x3,wuca3,yx3]=erfen(1,2,0.0001);
x3
toc

function y = funs(x)

y = x.^3 - 3 * x + 1;


function r=StepSearch(a,b,h,tol)
% 逐步搜索法算法
X=a:h:b;n=(b-a)/h+1;m=0;
Y=funs(X);
X(n+1)=X(n);Y(n+1)=Y(n);
k=2;
while(k<=n)
sk=Y(k)*Y(k-1);
if sk<=0
m=m+1;
if(abs(Y(k))<abs(Y(k-1)))
r(m)=X(k);
k=k+1;
else
r(m)=X(k-1);
end
else
xielv=(Y(k+1)-Y(k))* (Y(k)-Y(k-1));
if (abs(Y(k))<tol)&( xielv<=0)
m=m+1;r(m)=X(k);
end
end
k=k+1;

end




function [k,x,wuca,yx]=erfen(a,b,abtol)
% 二分法算法
a(1)=a; b(1)=b;

ya=funs(a(1)); yb=funs(b(1)); %程序中调用的fun.m为函数

if ya* yb>0

disp('注意:ya*yb>0,请重新调整区间端点a和b.'), return
end
max1=-1+ceil((log(b-a)- log(abtol))/log(2)); %ceil是向正方向取整
for k=1:max1+1

ya=funs(a); b; yb=funs(b); x=(a+b)/2;

yx=funs(x); wuca=abs(b-a)/2; k=k-1;
[k,a,b,x,wuca,ya,yb,yx];

if yx == 0
a=x;b=x;
elseif yb*yx>0
b=x;yb=yx;
else
a=x;ya=yx;

end
if b-a<abtol,return,end
end
k=max1;x;wuca;yx=funs(x);

% 简答与编程5 数值计算
% Test3
x=linspace(-5,5,10); % 已知数据点的x坐标
y=1./(1+x.^2); % 已知数据点y坐标
x0=linspace(-5,5,10); % 已知数据点x坐标
y0=1./(1+x0.^2); % 已知数据点y坐标
x1=linspace(-5,5,10);
y1=interp1(x,y,x1,'linear'); % 线性插值
y2=interp1(x,y,x1,'spline'); % 三次样条插值
y3=interp1(x,y,x1,'pchip'); % 三次Hermite插值
y4=interp1(x,y,x1,'nearest'); % 最邻近插值

% 作图
figure(1)
plot(x0,y0,'-',x,y,'og',x1,y1,'*r');
legend('被插值曲线','已知离散数据点','线性插值数据点 ','location','NorthWest');
title('interp with linear')
figure(2)
plot(x0,y0,'-',x,y,'og',x1,y4,'hr');
legend('被插值曲线','已知离散数据点','线性插值数据点 ','location','NorthWest');
title('interp with cubic')
figure(3)
plot(x0,y0,'-',x,y,'og',x1,y2,'sr');
legend('被插值曲线','已知离散数据点','线性插值数据点 ','location','NorthWest');
title('interp with spline')
figure(4)
plot(x0,y0,'-',x,y,'og',x1,y3,'dr');
legend('被插值曲线','已知离散数据点','线性插值数据点 ','location','NorthWest');
title('interp with pchip')

% 简答与编程5 数值计算
% Test4
x=1.23;
h=[0.1,0.01,0.001,0.0001];
x1=x+h;
x2=x-h;
y = 7.*x.*(sin(3.*x)+cos(3.*x));
y1= 7.*x1.*(sin(3.*x1)+cos(3.*x1));
y2=7.*x2.*(sin(3.*x2)+cos(3.*x2));
yCS=(y1-y2)./(2*h) % 差商数值求导
syms x;
f=7.*x.*(sin(3.*x)+cos(3.*x));
dy=diff(f,x); % 理论导数符号表达式
dyl=eval(subs(dy,x,1.23)) ;% 理论导数
detF=yCS-dyl % 差商求导误差

% Test 05

h=(exp(1)-1)/20;
x=1:h:exp(1);
y=2.*x.^3.*log(5*x);
z1=sum(y(1:20))*h;
z2=sum(y(2:21)*h);
z=(z1+z2)/2,z3=trapz(y)*h,z3h=trapz(x,y)

简答与编程六 符号计算

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
%  简答与编程六 符号计算
% Test 1
% 展开成傅立叶级数
l=1/2;
syms x n;
f=1-x^2;
a0=int(f*cos(0),-l,l)/l
an=int(f*cos(n*pi*x/l),-l,l)/l
bn=int(f*sin(n*pi*x/l),-l,l)/l

% 简答与编程六 符号计算
% Test 2
x = sym('x');
y = sym('y');
z = sym('z');
[xx,yy,zz]=solve(x-y^2+z==10,x+y-5*z==0,2*x-4*y+z==0',x,y,z);

% Test3
%%输入信号
t=0:1e-3:20;%时域信号的时间范围
x=sin(t)+sin(1.5*t+1)+5*cos(0.5*t)+2*randn(size(t));%时域信号x
w=[0:1e-2:2];%想要观察的频率范围
%%预定义
y=w;
a=w;
j=sqrt(-1);
%%计算频点
for i=1:length(w)
f=trapz(t,x.*exp(-j*w(i)*t));
y(i)=abs(f);
a(i)=angle(f);
end
%%输出
subplot(3,1,1),
plot(t,x)
subplot(3,1,2),
plot(w,y)
subplot(3,1,3),
plot(w,a)

% Test 04
% f1

s1=taylor(1/(5+cos(x)),x,5)

% f2
s2=taylor(exp(x* sin(x)),x,12)
% Test 05
% (1)求展开式,并求方程的根。
syms x;
f=(x^2+x)*(x-1);
g=x^2+2*x+1;
a=expand(f+g)
solve(f+g,x)
% (2)求 f(x)/g(x)的商式和余式
p1=sym2poly(f);
p2=sym2poly(g);
[Q,r]=deconv(p1,p2); % 其中Q是商式系数,r是余式系数
Qa=poly2sym(Q) % 商式
ra=poly2sym(r) % 余式
% Test 06
syms x y
f =x*y^2-y^3;
fx1=diff(f,x,1) % 对x的1阶
fx2=diff(f,x,2) % 对x的2阶

fy1=diff(f,y,1) % 对y的1阶
fy2=diff(f,y,2) % 对y的2阶
% Test 07
syms x;
f = (1+x)^(1/x);
a=limit(f,x,0)
% Test 08
% (1)
syms a x;
f1=sin(a*x);
a1=int(f1,0,pi/2)
% (2)
f2=x/log(x);
a2=int(f2,2,3)

% Test09
syms x y z
y1=@(x) sqrt(x);
y2=@(x) x.^2;
z1=@(x,y) sqrt(x.*y);
z2=@(x,y) x.^2.*y;
fun=@(x,y,z) x.^2+y.^2+z.^2;
a=integral3(fun,1,2,y1,y2,z1,z2)

% Test 10
syms x;
g=x^3-6*x^2+11*x-6;
% (1)因式
a1=factor(g)
% (2)嵌套式
a2=horner(g)
simplify(a2)

GUI Test

function varargout = Test03(varargin)

gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @Test03_OpeningFcn, …
‘gui_OutputFcn’, @Test03_OutputFcn, …
‘gui_LayoutFcn’, [] , …
‘gui_Callback’, []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
defaultanswers={‘5’};
answer=inputdlg(‘Enter your grade’,’Enter’,1,defaultanswers,’on’);
answer1=str2num(char(answer));
if answer1 >= 90 && answer1 <= 100
msgbox(“优秀”,’成绩分析’,’none’,’on’)
elseif answer1 >= 80 && answer1 <= 89
msgbox(“良好”,’成绩分析’,’none’,’on’)
elseif answer1 >= 70 && answer1 <= 79
msgbox(“中等”,’成绩分析’,’none’,’on’)
elseif answer1 >= 60 && answer1 <= 69
msgbox(“合格”,’成绩分析’,’help’,’on’)
else
msgbox(“不合格”,’Result’,’warn’,’on’)
end

% — Executes just before Test03 is made visible.
function Test03_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Test03 (see VARARGIN)

% Choose default command line output for Test03
handles.output = hObject;
ha=axes(‘units’,’normalized’,’pos’,[0 0 1 1]);

uistack(ha,’down’);

ii=imread(‘p1.jpg’);

%设置程序的背景图为p1.jpg

image(ii);

colormap gray

set(ha,’handlevisibility’,’off’,’visible’,’off’);

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Test03 wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% — Outputs from this function are returned to the command line.
function varargout = Test03_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% — Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes1

function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,’String’) returns contents of edit1 as text
% str2double(get(hObject,’String’)) returns contents of edit1 as a double

% — Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))
set(hObject,’BackgroundColor’,’white’);
end

function varargout = Test04(varargin)
% TEST04 MATLAB code for Test04.fig
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @Test04_OpeningFcn, …
‘gui_OutputFcn’, @Test04_OutputFcn, …
‘gui_LayoutFcn’, [] , …
‘gui_Callback’, []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
users={‘123’,’321’;’456’,’789’};% 存储一系列账号和密码
[x,y]=size(users);
prompt={‘请输入账号:’,’请输入密码:’}
name=’输入’;
numlines=1;
defaultanswer={‘000’,’000’};
input=inputdlg(prompt,name,numlines,defaultanswer);
input1=str2num(char(input));
for i=1:x
if input1(1)==str2num(char(users(i,1)))
if input1(2)==str2num(char(users(i,2)))
msgbox(‘欢迎登录本系统’,’Welcome ‘,’none’)
break
else
msgbox(‘输入有误,请重新输入账号和密码’,’出错’,’error’)
break
end
else
msgbox(‘输入有误,请重新输入账号和密码’,’出错’,’error’)
break
end
end

% — Executes just before Test04 is made visible.
function Test04_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Test04 (see VARARGIN)

% Choose default command line output for Test04
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Test04 wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% — Outputs from this function are returned to the command line.
function varargout = Test04_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;