如何定义在Matlab的结构 [英] How do i define a structure in Matlab
问题描述
我知道,一个结构可以通过多种方式,如所定义:
I know that a structure can be defined by in several ways such as:
-
添加字段变量
Adding fields to a variable
p.color.red = .2;
p.color.green = .4;
p.color.blue = .7;
通过转让定义标量结构
Defining a scalar structure by assignment
S = struct('a', 0, 'b', 1, 'c', 2);
我希望能够做的是建立一个结构定义(如C)。我的最终目标是有结构的数组,我可以遍历并执行测试上。有什么办法,我可以定义一个通用结构,然后创建它的实例?我应该使用一些其他机制。我知道MATLAB支持Java,我应该使用类/接口?
What I want to be able to do is create a structure definition (like C). My end goal is to have an array of structures that i can iterate through and perform testing on. Is there any way I can define a generic structure and then create instances of it? Should I use some other mechanism. I know MATLAB supports Java, should I use a class/interface?
推荐答案
与C,MATLAB允许您添加或你去从结构删除成员。它更与某些字段的结构可与某些功能使用的公约。
Unlike C, Matlab allows you to add or remove members from a struct as you go. It's more of a convention that a struct with certain fields can be used with certain functions.
所以,是的,这是两种基本的方法创建结构。当然,你总是可以写它创建为您某些字段结构的* .m文件的功能。或者,如果你想获得更多的面向对象,请参见 href=\"http://www.mathworks.com/help/techdoc/matlab_oop/ug_intropage.html\">
So yes, those are the two basic ways to create structures. Of course, you can always write a function in a *.m file which creates a structure with certain fields for you. Or if you want to get more OO, see here
这篇关于如何定义在Matlab的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!