如何在 MATLAB 中从 .fig 文件中提取数据?
我知道这确实很基础,但我对 MATLAB 很陌生。打开 .fig 文件后,如何在命令窗口中实际使用绘制的数据?我所看到的只是剧情。我不确定如何实际获取数据。
I know this is really basic, but I am new to MATLAB. After opening a .fig file, how do you actually work with the plotted data in the command window? All I see is the plot. I'm not sure how to actually get the data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实际上,您甚至不必显示图形即可获取数据。图文件以标准 Matlab MAT 格式存储,您可以使用内置的 load() 函数读取该格式。图形句柄和数据存储在您可以轻松理解和处理的结构中。
Actually, you don't even have to display the figure in order to get the data. FIG files are stored in the standard Matlab MAT format, that you can read using the built-in load() function. The figure handles and data are stored in a structure that you can easily understand and process.
这是一个非常简单的方法:
单击您想要从中获取数据的对象。不会有任何迹象表明您已单击它。
有时,单击线条或其他对象本身可能很困难。如果您遇到此问题,请单击包含您感兴趣的子项的轴,然后:
这将为您提供各个子项的句柄数组。您可以尝试通过对 kids 建立索引来一次获取一个数据,或者使用以下方法一次获取所有数据。这将以元胞数组的形式返回结果,如果您以前没有使用过它们,这可能会有点棘手:
Here's a really simple way:
Click on the object that you want to get the data from. There will be no indication that you have clicked on it.
Sometimes it can be hard to click on the line, or other object, itself. If you have this problem, click on the axes that contains the child(ren) you are interested in, then:
This will give you an array of handles to the various children. You can try getting them one at a time by indexing into kids, or use the following to get all data at once. This will return the results as a cell array, which can be a little tricky if you haven't used them before:
尝试 hgload,然后查看它返回的图形句柄结构。例如,如果您绘制并保存以下内容:
清除工作区,然后使用 hgload 打开保存的图形:
您可以通过调用检查图形的句柄 h
或通过调用进一步深入了解轴/标题/图例
如果您使用的是在我的示例中,您应该只有一个子图形,即轴。调用轴的孩子,你应该有一行。
接下来,调用该行的“Xdata”和“Ydata”字段,您就得到了原始数据。
如果你有一个比轴更复杂的图形,那就有点困难了。您需要探索每个子项以确定它是否是您想要从中提取数据的图。
Try hgload and then poke around the graphics handle structure it returns. For example, if you plot and save the following:
Clear your workspace, and open the saved figure using hgload:
You can inspect the figure's handle h by calling
Or delve further into the axes/titles/legends by calling
If you're using the code in my example, you should only have one child for the figure, which will be the axes. Call the children of the axes, and you should have one line.
Next, call the 'Xdata' and 'Ydata' fields of the line, and you have your original data.
If you have a more complicated figure than just axes, it gets a little tougher. You'll need to explore each child to determine if it's the plot you wanted to extract data from.
使用 HGLOAD 命令。参考此处。
Use the HGLOAD command. Reference available here.