Documentation Center

  • Trial Software
  • Product Updates

linkprop

Keep same value for corresponding properties of graphics objects

Syntax

hlink = linkprop(obj_handles,'PropertyName')
hlink = linkprop(obj_handles,{'PropertyName1','PropertyName2',...})

Description

Use linkprop to maintain the same values for the corresponding properties of different graphics objects.

    Note:   Use linkprop only with Handle Graphics® objects.

hlink = linkprop(obj_handles,'PropertyName') maintains the same value for the property PropertyName on all objects whose handles appear in obj_handles. linkprop returns the link object in hlink. See About Link Objects for more information.

hlink = linkprop(obj_handles,{'PropertyName1','PropertyName2',...}) maintains the same respective values for all properties passed as a cell array on all objects whose handles appear in obj_handles.

MATLAB® updates the linked properties of all linked objects immediately when linkprop is called. The first object in the list obj_handles determines the property values for the other objects.

A set of graphics objects can have only one link object connecting their properties at any given time. Calling linkprop creates a new link object. This new link object replaces any existing link object that is associated with the objects specified in obj_handles. However, you can manage which properties and which objects are linked by calling methods on that object:

  • To add an object to the list of linked objects, use the addtarget method.

  • To link new properties of currently-linked objects, use the addprop method.

  • To stop linking an object, use the removetarget method.

  • To stop properties from linking, use the removeprop method.

About Link Objects

The link object that linkprop returns stores the mechanism that links the properties of different graphics objects. Therefore, the link object must exist within the context where you want property linking to occur (such as in the base workspace if users are to interact with the objects from the command line or figure tools).

The following list describes ways to maintain a reference to the link object.

  • Return the link object as an output argument from a function and keep it in the base workspace while interacting with the linked objects.

  • Make the hlink variable global.

  • Store the hlink variable in an object's UserData property or in application data. See the Examples section for an example that uses application data.

Updating a Link Object

If you want to change either the graphics objects or the properties that are linked, you need to use the link object methods designed for that purpose. These methods are functions that operate only on link objects. To use them, you must first create a link object using linkprop.

Method

Purpose

addtarget

Add specified graphics object to the link object's targets.

removetarget

Remove specified graphics object from the link object's targets.

addprop

Add specified property to the linked properties.

removeprop

Remove specified property from the linked properties.

Method Syntax

ddtarget(hlink,obj_handles)
removetarget(hlink,obj_handles)
addprop(hlink,'PropertyName')
removeprop(hlink,'PropertyName')

Method Arguments

  • hlink — Link object returned by linkprop

  • obj_handles — One or more graphic object handles

  • PropertyName — Name of a property common to all target objects

Examples

This example creates four isosurface graphs of fluid flow data, each displaying a different isovalue. The CameraPosition and CameraUpVector properties of each subplot axes are linked so that the user can rotate all subplots in unison.

After running the example, select Rotate 3D from the figure Tools menu and observe how all subplots rotate together.

The property linking code is in step 3.

  1. Define the data using flow and specify property values for the isosurface (which is a patch object).

    [x,y,z,v] = flow;
    isoval = [-3,-1,0,1];
    props.FaceColor = [0,0,0.5];
    props.EdgeColor = 'none';
    props.AmbientStrength = 1;
    props.FaceLighting = 'gouraud';
  2. Create four subplot axes and add an isosurface graph to each one. Add a title and set viewing and lighting parameters. MATLAB functions used are subplot, patch, isosurface, title, and num2str. Also set the viewing and lighting parameters for each axes to be the same by calling view, axis, and camlight.

    figure
    % Preallocate h
    h = zeros(1,4);
    for k = 1:4
       h(k) = subplot(2,2,k);
       patch(isosurface(x,y,z,v,isoval(k)),props)
       title(h(k),['Isovalue = ',num2str(k)])
       % Set the view and add lighting
       view(h(k),3); axis(h(k),'tight','equal')
       camlight left; camlight right
       % Make axes invisible and title visible
       axis(h(k),'off')
       set(get(h(k),'title'),'Visible','on')
    end
  3. Link the CameraPosition and CameraTarget properties of all subplot axes. Since this code already is completed executing when you rotate the subplots, the link object is stored in the first subplot axes application data. See setappdata for more information on using application data.

    if ishghandle(h)
       hlink = linkprop(h,{'CameraPosition','CameraUpVector'});
       key = 'graphics_linkprop';
       % Store link object on first subplot axes
       setappdata(h(1),key,hlink);
    end

  4. Turn on the Rotate 3D tool. Click any object in the figure and rotate it. As you turn it, all three other subplots turn in the same manner.

    rotate3d on

Linking an Additional Property

Suppose you want to add the axes PlotBoxAspectRatio to the linked properties in the previous example. You can do this by modifying the link object that is stored in the first subplot axes' application data.

  1. First click the first subplot axes to make it the current axes (since its handle was saved only within the creating function). Then get the link object's handle from application data (getappdata).

    hlink = getappdata(gca,'graphics_linkprop');
  2. Use the addprop method to add a new property to the link object.

    addprop(hlink,'PlotBoxAspectRatio')

Since hlink is a reference to the link object (i.e., not a copy), addprop can change the object that is stored in application data.

See Also

| | | |

Was this topic helpful?