将变量从工作区保存到结构中
Save variables into a struct from the workspace
如图所示,我有三个变量,两个命名为number_of_steps_...
,第三个命名为struct
。
如何将number_of_steps
变量中保存的内容保存到struct
中?
我试过 save
命令,但它不能满足我的需要。正确的做法是什么?
我不知道你所说的 "save" 是什么意思,但你可以使用
将它们添加到结构中
mystruct.number_of_steps1 = number_of_steps1
mystruct.number_of_steps2 = number_of_steps2
然后使用
将结构保存到文件
save mystruct.mat mystruct
请注意,我冒昧地将变量 struct
重命名为 mystruct
。由于"struct" is a Matlab command,将其用作变量名不是一个好主意。
如图所示,我有三个变量,两个命名为number_of_steps_...
,第三个命名为struct
。
如何将number_of_steps
变量中保存的内容保存到struct
中?
我试过 save
命令,但它不能满足我的需要。正确的做法是什么?
我不知道你所说的 "save" 是什么意思,但你可以使用
将它们添加到结构中mystruct.number_of_steps1 = number_of_steps1
mystruct.number_of_steps2 = number_of_steps2
然后使用
将结构保存到文件save mystruct.mat mystruct
请注意,我冒昧地将变量 struct
重命名为 mystruct
。由于"struct" is a Matlab command,将其用作变量名不是一个好主意。