structexmple.m

来自「MATLAB的课件集合」· M 代码 · 共 35 行

M
35
字号
%%%struct01.m
clear student			%清除student变数
	student.name='洪鹏翔';%加入 name 字段
	student.id = 'mr871912';          % 加入 id 字段
	student.scores =[58, 75, 62];	% 加入 scores 字段
	student				% 秀出结果
    
    
%%%struct02
clear student			% 清除 student 变数
	student.name = '洪鹏翔';   	% 加入 name 字段
	student.id = 'mr871912';		% 加入 id 字段
	student.scores = [58, 75, 62];      % 加入 scores 字段
	% 以下是新加入的第二笔数据
	student(2).name = '邱中人';
	student(2).id = 'mr872510';
	student(2).scores = [25, 36, 92];
	student				%秀出结果
    student(1)
    student(2)
    
    
    %%%%范例3 : struct03.m
student = struct('name', {'张庭硕', '张庭安'}, 'scores', {[50 60], [60 70]});
	student(1)		% 显示 student(1)
	student(2)		% 显示 student(2)
    
    
   %%% 范例4 : struct04.m
student = struct('name', '张庭安','scores', {[50 60], [90 100]});
student(1)		% 显示 student(1)
student(2)		% 显示 student(2)


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?