0

I have figures (in Matlab's fig file format) each of which contains a line plot with two lines (representing EEG curves), axes, bunch of labels etc.

I want to:

  1. change the color of the lines
  2. remove some of the labels

I would loop over the fig files and do the same thing for each of them.

Is there a list of all the objects within the figure that I could index and edit? How can I get to those objects using commands (i.e. without the gui)?

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
jakub
  • 4,774
  • 4
  • 29
  • 46
  • You'll want to look at the [`Children`](http://www.mathworks.com/help/matlab/ref/figure-properties.html) of each figure to obtain the handle to your axes. The `Children` of the axes are the line object(s) that form your plot, which you can [address directly and modify](http://www.mathworks.com/help/matlab/ref/primitiveline-properties.html). Same goes for [the legend](http://www.mathworks.com/help/matlab/ref/legend-properties.html) but I don't remember if it's a child of the figure or of the axes; I would guess the axes. – sco1 Nov 27 '15 at 16:29
  • [`findobj`](http://www.mathworks.com/help/matlab/ref/findobj.html) may also be useful. – sco1 Nov 27 '15 at 16:30
  • 1
    This blog post may also be useful: [Editing an Existing Figure File in MATLAB](http://blogs.mathworks.com/videos/2014/12/19/editing-an-existing-figure-file-in-matlab/) – sco1 Nov 27 '15 at 16:34
  • It doesn't matter if edit one or a thousand. Once you know how to edit one you can proceed with a simple loop. Also see: http://stackoverflow.com/questions/9329611/matlab-changing-the-line-properties-of-a-loaded-figure#9332515 – NoDataDumpNoContribution Nov 27 '15 at 19:53

1 Answers1

3

Line, lable, etc. are children of axis, which is itself a child of a figure. What you need to do is acquire handles to the objects you want to change through this hierarchy.

% Get a handle to the figure 
hfig = openfig('testfig');

% Get all children of the CurrentAxes. Most of what you want is here.
axes_obj = allchild(hfig.CurrentAxes);

% Edit Axes object according to its type
For ii = 1:length(axes_obj)
    switch axes_obj(ii).Type
        case 'Text'
            % Do something, for example:
            axes_obj(ii).String = 'changed';
        case 'Line'
            % Do something, for example:
            axes_obj(ii).MarkerEdgeColor = 'b';
    end
end

% Save figure
savefig(hfig, 'testfig')

You can see all the properties of the object you wish to edit by simply typing axes_obj(ii) in the command window.

user3667217
  • 2,172
  • 2
  • 17
  • 29