##以下代码为matlab中代码%% chapter 5%%1 编制一个脚本 查找给定字符串中指定字符出现的次数和位置
clc
letter ='a';%%标记字母a
string ='Zhong Nan University Of Economics and Law';%%查找对象
places = findstr(string,letter)%%寻找letter(a) 出现的位置 并且显示出来 记录在place中
ntimes = length(places)%%通过length()函数计算place中的元素个数,进而表示a出现的次数
%%2 将每一个字符串小写改大写
clc
str='zhong nan university of economics and law';%%创造字符串
nlength = length(str);%%通过函数length()得到字符串str的长度
for k=1:nlength %%将其设置为循环次数
%判断每一个单词首字母是不是大写(通过对应asc码大小进行比较),若不是则将其修改为大写,其他字母为小写。
if(k==1|| isspace(str(k-1)))&&(str(k)<='z'&&str(k)>='a')str(k)= char(double(str(k))-32);
end
end
disp(str);%%3 创建 2×2 单元数组 并将其用图形表示
clc
cellA = cell(2,2);%%创建 2×2 单元数组
cellA(1,1)={'the first element of the cell'};%%第 1个元素为字符串
cellA(1,2)={'the second element of the cell'};%%第 2 个元素为字符串
cellA(2,1)={uint8(5)};%%第三个元素为整型变量
cellA(2,2)={[1,1;2,2]};%%第四个元素为双精度(double)类型
cellplot(cellA)%%绘制图形
%%4 创建一个结构体
clc
student_information=struct('name',{},'number',{},'scores',{})%%创建一个结构体
student_information=struct('name','liyuxiao','number','201821020247','scores','92.50')%%输入一个元素