This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Use Internet Explorer in MATLAB Figure

This example uses the ActiveX® control Shell.Explorer, which is exposed by the Microsoft® Internet Explorer® application, to include an HTML viewer in a MATLAB® figure. The figure's window button down function is then used to select a graphics object when the user clicks the graph and load the object's property documentation into the HTML viewer.

Techniques Demonstrated

  • Using Internet Explorer from an ActiveX client program.

  • Defining a window button down function that displays HTML property documentation for whatever object the user clicks.

  • Defining a resize function for the figure that also resizes the ActiveX object container.

Using the Figure to Access Properties

This example creates a larger than normal figure window that contains an axes object and an HTML viewer on the lower part of the figure window. By default, the viewer displays the URL When you issue a plotting command, such as:


the graph displays in the axes.

Click anywhere in the graph to see the property documentation for the selected object.

Complete Code Listing

You can open the file that implements this example in MATLAB Editor or you can run this example with the following links:

Creating the Figure

This example defines the figure size based on the default figure size and adds space for the ActiveX control. Here is the code to define the figure:

dfpos = get(0,'DefaultFigurePosition');
hfig = figure('Position',dfpos([1 2 3 4]).*[.8 .2 1 1.65],...
   'Menu','none','Name','Create a plot and click on an object',...

Note that the figure also defines a resize function and a window button down function by assigning function handles to the ResizeFcn and WindowButtonDownFcn properties. The callback functions reSize and wbdf are defined as nested functions in the same file.

Calculating the ActiveX Object Container Size

The actxcontrol function creates the ActiveX control inside the specified figure and returns the control's handle. You need to supply the following information:

  • Control's programmatic identifier (use actxcontrollist to find it)

  • Location and size of the control container in the figure (pixels) [left bottom width height]

  • Handle of the figure that contains the control:

conSize = calcSize;                                   % Calculate the container size
hExp = actxcontrol('Shell.Explorer.2',conSize,hfig);  % Create the control
Navigate(hExp,'');           % Specify content of html viewer

The nested function, calcSize calculates the size of the object container based on the current size of the figure. calcSize is also used by the figure resize function, which is described in the next section.

function conSize = calcSize
fp = get(hfig,'Position');              % Get current figure size
conSize = [0 0 1 .45].*fp([3 4 3 4]);   % Calculate container size
end % calcSize

Automatic Resize

In MATLAB, you can change the size of a figure and the axes automatically resize to fit the new size. This example implements similar resizing behavior for the ActiveX object container within the figure using the object's move method. This method enables you to change both size and location of the ActiveX object container (i.e., it is equivalent to setting the figure Position property).

When you resize the figure window, the MATLAB software automatically calls the function assigned to the figure's ResizeFcn property. This example implements the nested function reSize for the figure reSize function.

ResizeFcn at Figure Creation

The resize function first determines if the ActiveX object exists because the MATLAB software calls the figure resize function when the figure is first created. Since the ActiveX object has not been created at this point, the resize function simply returns.

When the Figure Is Resized

When you change the size of the figure, the resize function executes and does the following:

  • Calls the calcSize function to calculate a new size for the control container based on the new figure size.

  • Calls the control's move method to apply the new size to the control.

Figure ResizeFcn.  

function reSize(~,~)
if ~exist('hExp','var')
conSize = calcSize;
end % reSize

Selecting Graphics Objects

This example uses the figure WindowButtonDownFcn property to define a callback function that handles mouse click events within the figure. When you click the left mouse button while the cursor is over the figure, the MATLAB software executes the WindowButtonDownFcn callback on the mouse down event.

The callback determines which object was clicked by querying the figure CurrentObject property, which contains the handle of the graphics object most recently clicked. Once you have the object's handle, you can determine its type and then load the appropriate HTML page into the Shell.Explorer control.

The nested function wbdf implements the callback. Once it determines the type of the selected object, it uses the control Navigate method to display the documentation for the object type.

Figure WindowButtonDownFcn.  

function wbdf(~,~)
   cobj = get(hfig,'CurrentObject');
   if isempty(cobj)
   disp('Click somewhere else')
   pth = '';
   typ = get(cobj,'Type');
   switch typ
      case ('figure')
      case ('axes')
      case ('line')
      case ('image')
      case ('patch')
      case ('surface')
      case ('text')
      case ('hggroup')
end % wbdf
Was this topic helpful?