Matlab中的动态对象 [英] Dynamic Objects in Matlab

查看:84
本文介绍了Matlab中的动态对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种方案,只需在 for循环中输入 objects 的数量并输入所需的输出,即可创建动态对象和它们的变量是将初始化变量名和赋值 Matlab 中相应的位置向量数组. 但是,我尝试了 eval() ,但是它对我没有帮助,因为我想编写一个函数和其他复杂性,我进行了很多尝试,但可以找到适合我的方案的解决方案. 根据我的情况,应该有什么建议,无论有无功能. Edit1:位置矢量是预定义的.字符串,用于编号对象,它不是强制性的. 我的代码:

I have a scenario to create dynamic objects and also their variables by just entering the number of objects in for loop and the desired output is to initialize the variable name and assignment to corresponding array of position vector, in Matlab. However I tried eval() but it doesn't help me as i want to write a function and other complexities, I teried very much but could find the proper solution of my scenario. What suggestions should according to my scenario, may be with function or without. Position vector is predefined. String for number the object, its not compulsory. My Code:

function myFunc(n)
for ii=1:n
Obj(ii) = 'some string required with its number of ii';
 Obj(ii).position=position(ii);
end
end

推荐答案

您是否尝试过将对象分配给单元格结构?

Have you tried assigning your objects to a cell structure?

您可以定义具有两个位置索引的单元格结构,并且该单元格结构可以容纳其他对象,例如拟合对象,线性模型

You can define a cell structure with two position indices, and the cell structure can hold other objects, e.g. fit objects, linear models

models = cell(100,100) 
for i = 1:100
    for j = 1:100
        Obj{i,j} = ....  % where ... is your expression that generates an object
    end
end

从单元格结构内部,您可以打开对象并检查所有不同类型的变量,例如表格,双打,公式,单元格,str,字符数组等.

From inside the cell structure, you can open the object and inspect all the different types of variables, e.g. tables, doubles, formulas, cells, str, chararray etc.

这篇关于Matlab中的动态对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆