How to extract code from MATLAB Figure File

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 comentarios

Dr. O. Singh
Dr. O. Singh el 16 de Jul. de 2021
How to revert back .fig file from .docx file into MATLAB plot editor? Please help.
Rik
Rik el 16 de Jul. de 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.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Jun. de 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 comentarios

Abdur Rasheed
Abdur Rasheed el 6 de Jun. de 2017
Sir thanks for the response.Sir still I couldn't get the graph .I got the graph which is different than what it's drawn.Sir would you help me if I send you the fig file. Thanks a lot
Walter Roberson
Walter Roberson el 6 de Jun. de 2017
You can attach the fig file here. You can zip it before attaching
Abdur Rasheed
Abdur Rasheed el 16 de Jun. de 2017
Dear Sir! I am really indebted for your prompt response.It helps me a lot. Sir I have attached two files.The first file is old one in which non-parametric fit has been applied using matlab and in second file i have applied linear fit although i need non-parametric fit.Actually i want to extend my curve to Z=5.69 Point on Y-axis as shown in the graph. Sir kindly help me plot non-parametric fit for extrapolation of curve in the file name "CHINESE MOMENT WITHOUT LANE.JPG". Thanks a lot!
Abdur Rasheed
Abdur Rasheed el 17 de Jun. de 2017
Editada: Abdur Rasheed el 17 de Jun. de 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 el 17 de Jun. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 5 de Jun. de 2017

Comentada:

Rik
el 16 de Jul. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by