How can I extract text from a MATLAB Fig File
Show older comments
I am looking for a way to extract text from a table contained within a MATLAB figure file. I have tried using the children's attribute for gca, but the formatting is not always uniform. Is there a better method?

Thank you so much for your help
4 Comments
Walter Roberson
on 21 Jul 2020
Can you attach the .fig file for testing?
If the underlines and all are there, then it appears that someone went to a lot of trouble to format the text, but it was probably not processed in reading order (especially with the difference in font weights.)
Bryan Dighera
on 21 Jul 2020
dpb
on 21 Jul 2020
>> openfig('Negative P01(20).fig')
Warning: Could not find appropriate function on path loading function handle C:\Program Files (x86)\MATLAB71\spm8\spm_figure.m>myisresults
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Could not find appropriate function on path loading function handle C:\Program Files (x86)\MATLAB71\spm8\spm_figure.m>mydockspm
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Could not find appropriate function on path loading function handle C:\Program Files (x86)\MATLAB71\spm8\spm_figure.m>myclosefig
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Could not find appropriate function on path loading function handle C:\Program Files (x86)\MATLAB71\spm8\spm_figure.m>mysatfig
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Could not find appropriate function on path loading function handle C:\Program Files (x86)\MATLAB71\spm8\spm_figure.m>myisresults
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Could not find appropriate function on path loading function handle C:\Program Files (x86)\MATLAB71\spm8\spm_figure.m>mydockspm
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Could not find appropriate function on path loading function handle C:\Program Files (x86)\MATLAB71\spm8\spm_figure.m>myclosefig
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Could not find appropriate function on path loading function handle C:\Program Files (x86)\MATLAB71\spm8\spm_figure.m>mysatfig
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Could not find appropriate function on path loading function handle C:\Program Files (x86)\MATLAB71\spm8\spm_figure.m>spm_about
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Class 'nifti' is an unknown object class or does not have a valid 'loadobj' method. Element(s) of this class in array 'hgS_070000' have been converted to structures.
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
Warning: Class 'file_array' is an unknown object class or does not have a valid 'loadobj' method. Element(s) of this class in array 'hgS_070000' have been converted to structures.
> In matlab.graphics.internal.figfile.FigFile/read (line 33)
In matlab.graphics.internal.figfile.FigFile
In loadFigure (line 31)
In openfig>localOpenFigure (line 75)
In openfig (line 40)
ans =
Figure (Graphics) with properties:
Number: 1.00
Name: 'SPM8 (Wu Lab): Graphics'
Color: [1.00 1.00 1.00]
Position: [0.19 0.01 0.40 0.92]
Units: 'normalized'
Show all properties
>>
Looks like whoever will also probably have to have the package to get very far--if can even then...
Walter Roberson
on 22 Jul 2020
The text table is inside an axes, and consists of a whole bunch of individual text() objects. The text objects are intended for multiple "pages", with there being a control to select between pages.
If you findobj() the figure with 'Tag', 'NextPage', and look at its UserData, then it will be a cell array in which the entries are Text objects. The different cells represent different "pages" {1,1} looks like it is the handles of the objects on the first page and {2,1} looks like it is the handles of the objects on the second page. It sets them visible or not as required.
So you have to grab those sets of handles to make sense of what is on which page. And you should probably sort the coordinates as they will not necessarily have been plotted in order (and they would appear in reverse order of plotted anyhow.)
Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!