How to extract figure data in MATLAB

Recently, I had to deal with a set of data, some from experiments, and some obtained using MATLAB “Curve Fitting Tool”. As much as I like MATLAB figures, I usually find Excel features more desirable for good-looking plots! So, I needed to extract the data of Curve Fitting Tool. Here is what I did:

Save the figure as a “.fig” file.

Make a m-file with the following code to get the x, y data of the curve!

% Reads the figure file

% Gets the object of type line from the figure

% Obtains the "x" and "y" data of the curves

Then you have access to the data, and you can get the arrays as

% Assuming there are only 2 curves in the figure
% Gets the data as arrays

% x-values of 2 curves
x_data_curve_fit = x_data {1,1};
x_data_experimental = x_data{1,2};

% y-values of 2 curves
y_data_curve_fit = y_data {1,1};
y_data_experimental = y_data{1,2};

Then, your data is ready to copy/export to Excel.

1 comment

  1. Hi, this is an excellent post which truly saved me a lot of time. I just want to add however that when you have multiple plots (in my case, 4) in the figure, then the indexing seems to be the reverse of what you say. For example, in order to get the y-values of the third plot/line, I use the curly braces like this: {3, 1} and not {1, 3}. This is perhaps a consequence of how the other person saved her plots, I don’t know.

    Kheeli mamnoun!

Leave a Reply