MATLAB学习与使用:结构数组(struct)的创建

 时间:2024-11-01 12:29:59

1、第一,通过“.”创建结构数组。在命令行窗口输入如下代码:student.name='Jason'; student.class='class 3';student.results={'English','Maths';85,95};student.system=[1,2,3;4,5,6;7,8,9];然后输入student,按回车查看创建的结构数组student,返回如下结果:student = name: 'Jason' class: 'class 3' results: {2x2 cell} system: [3x3 double]同时看到工作区出现名称为student,值为1*1的结构数组。

MATLAB学习与使用:结构数组(struct)的创建

2、第二,通过struct函数创建结构数组。在命令行窗口输入clear all; clc按回车,清空命令行窗口,然后输入如下代洁船诼抨码:student=struct('name','Jason','class','class 3','results',{'English','Maths';85,95},'system',[1,2,3;4,5,6;7,8,9]);然后输入student,按回车查看创建的结构数组student,返回如下结果:student =2x2 struct array with fields: name class results system同时看到工作区出现名称为student,值为2*2的结构数组。

MATLAB学习与使用:结构数组(struct)的创建

3、第三,通过“.”创建高维的结构数组。在命令行窗口输入clear all; clc按回车,清空命令行窗口,然后输入如下代洁船诼抨码:student(1).name='Jason'; student(2).name='Chet';student(1).class='class 3'; student(2).class='class 3';student(1).results={'English','Maths';85,95}; student(2).results={'English','Maths';75,65};student(1).system=[1,2,3;4,5,6;7,8,9]; student(2).system=magic(3);然后输入student,按回车查看创建的结构数组student,返回如下结果:student =1x2 struct array with fields: name class results system同时看到工作区出现名称为student,值为1*2的结构数组。

MATLAB学习与使用:结构数组(struct)的创建

4、第四,通过struct函数创建高维的结构数组。在命令行窗口输入clear all; clc岳蘖氽颐按回车,清空命令行窗口,然后输入如下代码:student=struct('name',{'Jason','Chet'},'class',{'class 3','class 3'},'results',...{{'English','Maths';85,95},{'English','Maths';75,65}},'system',{[1,2,3;4,5,6;7,8,9],magic(3)});然后输入student,按回车查看创建的结构数组student,返回如下结果:student =1x2 struct array with fields: name class results system同时看到工作区出现名称为student,值为1*2的结构数组。

MATLAB学习与使用:结构数组(struct)的创建

5、第五,在命令行窗口输入doc struct,然后按回车,可以查看帮助文档对关结构数组的介绍。

MATLAB学习与使用:结构数组(struct)的创建
  • 如何用matlab进行图像的分割?
  • matlab中cell元胞数组的使用方法和实例
  • MATLAB中reshape的用法
  • matlab怎么把for循环中的数据存入到数组中
  • matlab中for循环怎么用
  • 热门搜索
    读书的手抄报图片 手抄报排版设计 消防手抄报资料 教师节手抄报大全 猴年春节手抄报 好书伴我行手抄报 我心中的祖国手抄报 有关大自然的手抄报 国庆节的手抄报图片简单又漂亮 争当美德少年手抄报