Products & Services Solutions Academia Support User Community Company

Learn more about Stateflow   

Using the Stateflow Search & Replace Tool

Opening the Search & Replace Tool

To open the Search & Replace dialog box:

  1. Open a chart in the Stateflow Editor.

  2. Select Tools > Search & Replace.

The window name for the Search & Replace dialog box contains a full path expression for the current Stateflow chart or machine in this form.

(object) Machine/Subsystem/Chart

The Search & Replace dialog box contains these fields:

Using Different Search Types

Enter search pattern text in the Search for text box. You can use one of the following settings in the Match options field (unlabeled and just to the right of the Search in field) to further refine the meaning of the text entered.

Contains word

Select this option to specify that the search pattern text is a whole word expression used in a Stateflow chart with no specific beginning and end delimiters. In other words, find the specified text in any setting.

Suppose you have a state with this label and entry action.

Searching for the string fail with the Contains word option finds two occurrences of the string fail.

Match case (Case Sensitive)

By selecting the Match case option, you enable case-sensitive searching. In this case, the Search & Replace tool finds only text matching the search pattern exactly.

By clearing the Match case option, you enable case-insensitive searching. In this case, search pattern characters entered in lower- or uppercase find matching text strings with the same sequence of base characters in lower- or uppercase. For example, the search string "AnDrEw" finds the matching text "andrew" or "Andrew" or "ANDREW".

Match whole word

Select this option to specify that the search pattern text in the Search for field is a whole word expression used in a Stateflow chart with beginning and end delimiters consisting of a blank space or a character that is not alphanumeric and not an underscore character (_).

In the previous example of a state named throt_fail, if Match whole word is selected, searching for the string fail finds no text within that state. However, searching for the string "fail_state" does find the text "fail_state" as part of the second line since it is delimited by a space at the beginning and a left square bracket ([) at the end.

Regular expression

Set the Match options field to Regular expression to search for text that varies from character to character within defined limits.

A regular expression is a string composed of letters, numbers, and special symbols that defines one or more string candidates. Some characters have special meaning when used in a regular expression, while other characters are interpreted as themselves. Any other character appearing in a regular expression is ordinary, unless a back slash (\) character precedes it.

If the Match options field is set to Regular expression in the previous example of a state named throt_fail, searching for the string "fail_" matches the "fail_" string that is part of the second line, character for character. Searching with the regular expression "\w*_" also finds the string "fail_". This search string uses the regular expression shorthand "\w" that represents any part-of-word character, an asterisk (*) that represents any number of any characters, and an underscore (_) that represents itself.

For a list of regular expression meta characters, see Regular Expressions in the MATLAB software documentation.

Searching with Regular Expression Tokens

Within a regular expression, you use parentheses to group characters or expressions. For example, the regular expression "and(y|rew)" matches the text "andy" or "andrew". Parentheses also have the side effect of remembering what they match so that you can recall and reuse the found text with a special variable in the Search for field. These variables are called tokens.

For details on how to use tokens in the Search & Replace tool, see Tokens in the MATLAB software documentation.

You can also use tokens in the Replace with field. See Replacing with Tokens for a description of using regular expression tokens for replacing.

Preserve case

This option modifies replacement text and not search text. For details, see Replacing with Case Preservation.

Specifying the Search Scope

You specify the scope of your search by selecting from the field regions discussed in the topics that follow.

Search in

You can select a whole machine or individual Stateflow chart for searching in the Search in field. By default, the current Stateflow chart in which you entered the Search & Replace tool is selected.

To select a machine, follow these steps:

  1. Select the down arrow of the Search in field.

    A list of the currently loaded machines appears with the current machine expanded to reveal its Stateflow charts.

  2. Select a machine.

To select a Stateflow chart for searching, follow these steps:

  1. Select the down arrow of the Search in field again.

    This list contains the previously selected machine expanded to reveal its Stateflow charts.

  2. Select a chart from the expanded machine.

Object Types

Limit your search to text matches in the selected object types by following these steps:

  1. Expand the Object types field.

  2. Select one or more object types.

Field Types

Limit your search to text matches for the specified fields by following these steps:

  1. Expand the Field types field.

  2. Select one or more field types

Available field types are as follows.

Names.   Machines, charts, data, and events have valid Name fields. States have a Name defined as the top line of their labels. You can search and replace text belonging to the Name field of a state in this sense. However, if the Search & Replace tool finds matching text in a state's Name field, the rest of the label is subject to later searches for the specified text whether or not the label is chosen as a search target.

Labels.   Only states and transitions have labels.

Descriptions.   All objects have searchable Description fields.

Document links.   All objects have searchable Link fields.

Custom code.   Only target objects contain custom code.

Using the Search Button and View Area

This topic contains the following subtopics:

Click Search to initiate a single-search operation. If an object match is made, its text fields are displayed in the Viewer pane in the middle of the Search & Replace dialog box. If the object is graphical (state, transition, junction, chart), the matching object appears highlighted in a Portal pane below the Viewer pane.

A Breakdown of the View Area

The view area of the Search & Replace dialog box displays matching text and its containing object, if viewable. In the previous example, taken from the sf_pool model, a search for the word "friction" finds the Description field for the state TotalDynamics. The resulting view area consists of these parts:

Icon.   Displays an icon appropriate to the object containing the matching text. These icons are identical to the icons in the Model Explorer that represent Stateflow objects displayed in Viewing Stateflow Objects in the Model Explorer.

Full Path Name of Containing Object.   This area displays the full path name for the object that contains the matching text:

(<type>) <machine name>/<subsystem>/<chart 
name>.[p1]...[pn].<object name> (<id>)

where p1 through pn denote the object's parent states.

To display the object, click the mouse once on the full path name of the object. If the object is a graphical member of a Stateflow chart, it appears in the Stateflow Editor. Otherwise, it appears as a member of its Stateflow chart in the Model Explorer.

Viewer.   This area displays the matching text as a highlighted part of all search-qualified text fields for the owner object. If other occurrences exist in these fields, they too are highlighted, but in lighter shades.

To invoke the properties dialog box for the owner object, double-click anywhere in the Viewer pane.

Portal.   This area contains a graphic display of the object that contains the matching text. That object appears highlighted.

To display the highlighted object in the Stateflow Editor, double-click anywhere in the Portal pane.

The Search Order

If you specify an entire machine as your search scope in the Search in field, the Search & Replace tool starts searching at the beginning of the first chart of the model, regardless of the Stateflow chart that appears in the Stateflow Editor when you begin your search. After searching the first chart, the Search & Replace tool continues searching each chart in model order until all charts for the model have been searched.

If you specify a Stateflow chart as your search scope, the Search & Replace tool begins searching at the beginning of the chart. The Search & Replace tool continues searching the chart until all the chart objects have been searched.

The search order when searching an individual chart for matching text is equivalent to a depth-first search of the Model Explorer. Starting at the highest level of the chart, the Model Explorer hierarchy is traversed downward from parent to child until an object with no child is encountered. At this point, the hierarchy is traversed upward through objects already searched until an unsearched sibling is found and the process repeats.

Additional Display Options

Right-click anywhere in the Search & Replace dialog box to display a menu with these selections.

Selection

Result

Show portal

A toggle switch that hides or displays the portal.

Edit

Displays the object with matching text in the Stateflow Editor. Applies to states, junctions, transitions, and charts.

Explore

Displays the object with matching text in the Model Explorer. Applies to states, data, events, machines, charts, and targets.

Properties

Displays the properties dialog box for the object with matching text.

If the portal is not visible, you can select the Show portal option to display it. You can also click and drag the border between the viewer and the portal (the cursor turns to a vertical double arrow), which resides just above the bottom boundary of the Search & Replace dialog box. Moving this border allows you to exchange area between the portal and the viewer. If you click and drag the border with the left mouse button, the graphic display resizes after you reposition the border. If you click and drag the border with the right mouse button, the graphic display continuously resizes as you move the border.

Specifying the Replacement Text

The Search & Replace tool replaces matching text with the exact (case-sensitive) text you entered in the Replace With field unless you choose one of the dynamic replacement options described below.

Replacing with Case Preservation

If you choose the Case Preservation option, matching text is replaced based on one of these conditions:

Replacing with Tokens

Within a regular expression, you use parentheses to group characters or expressions. For example, the regular expression "and(y|rew)" matches the text "andy" or "andrew". Parentheses also have the side effect of remembering what they matched so that you can recall and reuse the matching text with a special variable in the Replace with field. These variables are called tokens.

Tokens outside the search pattern have the form $1,$2,...,$n (n<17) and are assigned left to right from parenthetical expressions in the search string.

For example, the search pattern "(\w*)_(\w*)" finds all word expressions with a single underscore separating the left and right sides of the word. If you specify an accompanying replacement string of "$2_$1", you can replace all these expressions by their reverse expression with a single Replace all. For example, the expression "Bill_Jones" is replaced by "Jones_Bill", and the expression "fuel_system" is replaced by "system_fuel".

For details on how to use tokens in regular expression search patterns, see Regular Expressions in the MATLAB software documentation.

Using the Replace Buttons

You can activate the replace buttons (Replace, Replace All, Replace All in This Object) only after a search that finds text.

Replace

When you select the Replace button, the current instance of text matching the text string in the Search for field is replaced by the text string you entered in the Replace with field. The Search & Replace tool then searches for the next occurrence of the Search for text string.

Replace All

When you select the Replace All button, all instances of text matching the Search for field are replaced by the text string entered in the Replace with field. Replacement starts at the point of invocation to the end of the current Stateflow chart. If you initially skip through some search matches with the Search button, these matches are also skipped when you select the Replace All button.

If the search scope is set to Search Whole Machine, then after finishing the current Stateflow chart, replacement continues to the completion of all other charts in your Simulink model.

Replace All in This Object

When you select the Replace All in This Object button, all instances of text matching the Search for field are replaced by text you entered in the Replace with field everywhere in the current Stateflow object regardless of previous searches.

Search and Replace Messages

Informational and warning messages appear in the Full Path Name Containing Object field along with a defining icon.

– Informational Messages

– Warnings

The following messages are informational:

Please specify a search string

A search was attempted without a search string specified.

No Matches Found

No matches exist in the selected search scope.

Search Completed

No more matches exist in the selected search scope.

The following warnings refer to invalid conditions for searching or replacing:

Invalid option set

The object types and field types that you selected are incompatible. For example, a search on Custom Code fields without selecting target objects is invalid.

Match object not currently editable

The matching object is not editable by replacement due to one of these problems.

Problem

Solution

A simulation is running.

Stop the simulation.

You are editing a locked library block.

Unlock the library.

The current object or its parent has been manually locked.

Unlock the object or its parent.

The following warnings appear if the Search & Replace tool must find the object again and its matching text field. If the original matching object is deleted or changed before an ensuing search or replacement, the Search & Replace tool cannot continue.

Search object not found

If you search for text, find it, and then delete the containing object, this warning appears if you continue to search.

Match object not found

If you search for text, find it, and then delete the containing object, this warning appears if you perform a replacement.

Match not found

If you search for text, find it, and then change the object containing the text, this warning appears if you perform a replacement.

Search string changed

If you search for text, find it, and then change the Search For field, this warning appears if you perform a replacement.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS