1 | % Test 1 |
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
courseTest 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)*bTest 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 | % 简答与编程三 数据可视化 |
简答与编程六 符号计算
1 | % 简答与编程六 符号计算 |
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;