How to extract code from MATLAB Figure File
56 views (last 30 days)
Show older comments
Hi Everyone! I'm having a problem of extracting of code from a MATLAB figure.Actually,i have to plot a non-parametric fit of a CDF(Commulative Distribution Function) curve.I got a MATLAB figure but i don't know how it was plotted.so i need its code.Kindly help me if someone knows about it as i need it urgently.I tried a lot but couldn't find it. Thanks a lot!
4 Comments
Dr. O. Singh
on 16 Jul 2021
How to revert back .fig file from .docx file into MATLAB plot editor? Please help.
Rik
on 16 Jul 2021
@Dr. O. Singh That is only possible if only the extension was changed, so only if your file wasn't a real docx file. You will have to rebuild it yourself.
Accepted Answer
Walter Roberson
on 5 Jun 2017
openfig() the fig file to display it on the screen. Does it have a File menu? If it does, use that menu to Generate Code. That will create a function that, given data as input, would display the data in the same way as the fig file has.
The step after that is to extract the data from the fig file. You can mostly do that by
xd_handles = findobj(FigureHandle, '-property', 'xdata');
h_type = get(xd_handles, 'Type');
xd = get(xd_handles, 'XData');
yd = get(xd_handles, 'YData');
zd = get(xd_handles, 'ZData');
The step after that would be to match the data produced to the individual graph. The complexity of that depends upon whether you are using subplots, and the number of lines you have drawn within each plot, and on what kind of graphic objects you are using.
Note that the result of all of this is just to tell you how the data was plotted, not how the data was calculated. Or rather, how the data could have been plotted. For example the original program might have used pcolor() but the generated code would instead use surface() as pcolor is implemented as surface() followed by view().
5 Comments
Walter Roberson
on 17 Jun 2017
"I couldn't get the graph"
I tested with the .fig you included, using the steps that I posted above about Generate Code, and extracting the x data and y data and then calling the new function with the x and y data. That did a quite reasonable job of recreating the graph. There is a minor difference in the ylim as the original .fig does not quite show all of the data on the plot.
The largest difference is that the sequence I describe does not build the Ezyfit menu that the original figure has.
Also, the .fig has a CreateFcn callback for the figure, asking to invoke 'efmenu'.
It looks to me as if you are using the File Exchange Contribution https://www.mathworks.com/matlabcentral/fileexchange/10176-ezyfit-2-44; if so then probably the best thing would be to extract the x and y data like I indicated, and then run the code again to do the fitting and displaying.
When I look at that graph, I would say that a linear fig would not be appropriate. When I use cftool, two possibilities that looked sort of plausible were the 5th degree polynomial, or a third degree polynomial divided by a 2nd degree polynomial.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!