How to automatically extract/save data from figure?
显示 更早的评论

Hello dear colleagues Please, how can I automatically extract and save data (x,y) from Figure.fig. This figure is incremented by 02Hours (0:2:24), so I'll have 13 data (I do this manually, hard to do with 10000 fig). The output file will can be in .txt .mat
6 个评论
Walter Roberson
2020-7-25
I got part way through but realized that I am not clear as to how the data is being represented in your graph.
The partial framework I developed follows. Depending on what is in your graph, it might potentially need significant changes.
filename = 'NameOfFig.fig';
fig = openfig(filename);
obj_with_x = findobj(fig, '-property', 'XData');
if isempty(obj_with_x)
fprintf('Opps, file "%s" has no objects with XData\n', filename);
else
if ~iscell(obj_with_x)
obj_with_x = {obj_with_x};
end
xvals = cellfun(@(OBJ) obj.XData(:), obj_with_x, 'uniform', 0);
yvals = cellfun(@(OBJ) obj.YData(:), obj_with_y, 'uniform', 0);
xvals = cell2mat(xvals);
yvals = cell2mat(yvals);
end
Abdennasser TACHEMA
2020-7-25
Image Analyst
2020-7-25
If he does that (which he won't) then you'll be preventing anyone else from helping you. There is no reason it can't be solved here.
You forgot to give us the code for how the figure you mentioned was created. Please post that. Also, if you put the data into a figure, then you already HAVE the data and so there is no need to extract it back out from the axes control on the figure. If you need more help, please attach your data and the code you used to read it in and create your figure from it.
Walter Roberson
2020-7-25
Or even just the .fig -- since the task is to extract from a .fig it is the .fig that we need to deal with.
Abdennasser TACHEMA
2020-9-1
Rik
2020-9-1
I'm assuming you mean you have 5 .m files that create your figures. Not all of those are required for this problem. Your data means something to you, but whether a value is 1 or 1000 doens't matter to the method that extracts the data.
You have two options:
- Attach the all files required to create the figures with your real data.
- Write code that will generate random data and create the plots you need.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!