0
votes

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)?

1
You'll want to look at the Children 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. Same goes for the legend but I don't remember if it's a child of the figure or of the axes; I would guess the axes. - excaza
findobj may also be useful. - excaza
This blog post may also be useful: Editing an Existing Figure File in MATLAB - excaza
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: stackoverflow.com/questions/9329611/… - Trilarion

1 Answers

3
votes

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.