Matlab(Octave)结构是否有切片运算符将它们转换为标量数组或向量并返回?
在 Matlab 或 GNU Octave 中,我想做这样的事情:
x=struct('a',1,'b',2,'c',[1 2;3 4])
y=x(:) % array-ification of a struct
save -ascii y.txt y
z=load('y.txt')
x(:)=z % struct-ification of an array
我想序列化/pickle 一个结构并稍后重新创建它,从而允许在其他语言中轻松读取/保存/操作。我更喜欢中间形式是 ascii 文本而不是二进制,以方便人类阅读/编辑/调试。
我是否忘记了一些类似 (:) 的巧妙的结构或单元数组切片?
In Matlab or GNU Octave I'd like to do something like this:
x=struct('a',1,'b',2,'c',[1 2;3 4])
y=x(:) % array-ification of a struct
save -ascii y.txt y
z=load('y.txt')
x(:)=z % struct-ification of an array
I want to serialize/pickle a structure and recreate it later, allowing easy read/save/manipulate in other languages. I'd prefer the intermediate form to be ascii text rather than binary to facilitate human reading/editing/debugging.
Am I forgetting some clever (:)-like slicing for structs or cell arrays?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你想要的是这样的:
但我不认为你可以轻松地从结果文件中重新创建它:存在数据丢失(字段名丢失)。如果您不使用 -ascii 选项,则可以使用以下方法完全重新创建它:
另外,加载只能加载 ASCII 文本数字的矩形数组(请参阅 http://www.mathworks.com/help/techdoc/ref/save.html 和 http://www.mathworks.com/help/techdoc/ref/load.html 的限制)。如果您希望将结构体的字段保留为序列化形式,您可以查看“fieldnames”函数。
I think what you want is something like:
But I do not think you can easily recreate it from the resulting file: there is data loss (the fieldnames are lost). If you don't use the -ascii option, it can be fully recreated using:
Additionally load can only load a rectangular array of numbers of ASCII text (see http://www.mathworks.com/help/techdoc/ref/save.html and http://www.mathworks.com/help/techdoc/ref/load.html for the limitations). If you wish to keep the fields of the struct in your serialized form, you might look into the "fieldnames" function.
是的,有:),
Yes, there is :),