How to extract code from MATLAB Figure File

70 vues (au cours des 30 derniers jours)
Abdur Rasheed
Abdur Rasheed le 5 Juin 2017
Commenté : Rik le 16 Juil 2021
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 commentaires
Dr. O. Singh
Dr. O. Singh le 16 Juil 2021
How to revert back .fig file from .docx file into MATLAB plot editor? Please help.
Rik
Rik le 16 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Juin 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 commentaires
Abdur Rasheed
Abdur Rasheed le 17 Juin 2017
Modifié(e) : Abdur Rasheed le 17 Juin 2017
@the cyclist @Wayne King @Mischa Kim @Teja Muppirala @AJ von @Alt Brendan Hamm Please tell me whether i can use linear fit or not ?Secondly,how can i apply non-parametric fit ? I have applied linear fit but i want to use non-parametric fit for extrapolation of my plot (curve).. Thanks a lot !
Walter Roberson
Walter Roberson le 17 Juin 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by