如何在 MATLAB 中从 .fig 文件中提取数据?

发布于 2024-09-04 16:44:45 字数 85 浏览 3 评论 0原文

我知道这确实很基础,但我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

━╋う一瞬間旳綻放 2024-09-11 16:44:45

实际上,您甚至不必显示图形即可获取数据。图文件以标准 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.

在你怀里撒娇 2024-09-11 16:44:45

这是一个非常简单的方法:

单击您想要从中获取数据的对象。不会有任何迹象表明您已单击它。

>> xd = get(gco,'XData');
>> yd = get(gco,'YData');

有时,单击线条或其他对象本身可能很困难。如果您遇到此问题,请单击包含您感兴趣的子项的轴,然后:

>> kids = get(gca,'Children');

这将为您提供各个子项的句柄数组。您可以尝试通过对 kids 建立索引来一次获取一个数据,或者使用以下方法一次获取所有数据。这将以元胞数组的形式返回结果,如果您以前没有使用过它们,这可能会有点棘手:

>> xd = get(kids,'XData');
>> yd = get(kids,'YData');
>> xd1 = xd{1}; %# X Data from first line

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.

>> xd = get(gco,'XData');
>> yd = get(gco,'YData');

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:

>> kids = get(gca,'Children');

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:

>> xd = get(kids,'XData');
>> yd = get(kids,'YData');
>> xd1 = xd{1}; %# X Data from first line
有木有妳兜一样 2024-09-11 16:44:45

尝试 hgload,然后查看它返回的图形句柄结构。例如,如果您绘制并保存以下内容:

x=0:.01:10;
y=sin(x);
h=plot(x,y);
saveas(h,'testfigure.fig');

清除工作区,然后使用 hgload 打开保存的图形:

clear
close all
h=hgload('testfigure.fig');

您可以通过调用检查图形的句柄 h

get(h)

或通过调用进一步深入了解轴/标题/图例

ch=get(h,'Children');

如果您使用的是在我的示例中,您应该只有一个子图形,即轴。调用轴的孩子,你应该有一行。

l=get(ch,'Children');

接下来,调用该行的“Xdata”和“Ydata”字段,您就得到了原始数据。

x=get(l,'Xdata');
y=get(l,'Ydata');

如果你有一个比轴更复杂的图形,那就有点困难了。您需要探索每个子项以确定它是否是您想要从中提取数据的图。

Try hgload and then poke around the graphics handle structure it returns. For example, if you plot and save the following:

x=0:.01:10;
y=sin(x);
h=plot(x,y);
saveas(h,'testfigure.fig');

Clear your workspace, and open the saved figure using hgload:

clear
close all
h=hgload('testfigure.fig');

You can inspect the figure's handle h by calling

get(h)

Or delve further into the axes/titles/legends by calling

ch=get(h,'Children');

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.

l=get(ch,'Children');

Next, call the 'Xdata' and 'Ydata' fields of the line, and you have your original data.

x=get(l,'Xdata');
y=get(l,'Ydata');

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.

丶视觉 2024-09-11 16:44:45

使用 HGLOAD 命令。参考此处

Use the HGLOAD command. Reference available here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文