x***d 发帖数: 227 | 1 e.g,我有一个变量 order = 1:100
我想得到 100个变量,每个变量有不同数值,
变量的名字定义为: design_order = order;
也就是想得到:
design_1 = 1;
design_2 = 2;
......
design_100 = 100;
请问如生成 design_1, ..., design_100
多谢 | f*****g 发帖数: 30 | 2 用eval,可以动态生成要执行的命令。例如:
for id=1:100
eval(sprintf('design_%d = %d',id,id));
end; | x***d 发帖数: 227 | 3 thanks
【在 f*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 用eval,可以动态生成要执行的命令。例如: : for id=1:100 : eval(sprintf('design_%d = %d',id,id)); : end;
| k**f 发帖数: 372 | 4
While you can do this following fouyang (西门侠)'s method, maybe it is
better to think twice about doing so.
If the variables are of the same type and size, why not use an array, such
as design? It is much easier to use an index to refer to individual ones
like design(k), and also easy to scale to 200 or 50 entries.
【在 x***d 的大作中提到】![](/moin_static193/solenoid/img/up.png) : e.g,我有一个变量 order = 1:100 : 我想得到 100个变量,每个变量有不同数值, : 变量的名字定义为: design_order = order; : 也就是想得到: : design_1 = 1; : design_2 = 2; : ...... : design_100 = 100; : 请问如生成 design_1, ..., design_100 : 多谢
|
|