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 Comments

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
Hello Dear Walter Roberson
Thank you so much for your response, I tried but without any results.
Please, can I contact you with email, messenger or whatsup (for showing you my own problem)?
Thank you again
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.
Or even just the .fig -- since the task is to extract from a .fig it is the .fig that we need to deal with.
Hello, I know that you can't understand 5 matlab code (.mat) each one with 500 lines.
I posted the question overall.
Thank you to help me again
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:
  1. Attach the all files required to create the figures with your real data.
  2. Write code that will generate random data and create the plots you need.

Sign in to comment.

Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Asked:

on 25 Jul 2020

Commented:

Rik
on 1 Sep 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!