How to extract code from MATLAB Figure File

56 visualizaciones (últimos 30 días)
Abdur Rasheed
Abdur Rasheed el 5 de Jun. de 2017
Comentada: Rik el 16 de Jul. de 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 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 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)

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by