How to automatically extract/save data from figure?
Show older comments

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 Comments
Walter Roberson
on 25 Jul 2020
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
on 25 Jul 2020
Image Analyst
on 25 Jul 2020
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
on 25 Jul 2020
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
on 1 Sep 2020
Rik
on 1 Sep 2020
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.
Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!