Use the Search and Replace Tool

Open the Search & Replace Tool

To open the Search & Replace dialog box:

  1. Open a chart.

  2. Select Edit > Find & Replace in Chart.

The Search & Replace dialog box contains the following fields:

  • Search for

    Enter search pattern text in the Search for text box. You can select the interpretation of the search pattern with the Match case check box and the Match options field (unlabeled and just to the right of the Search in field).

  • Match case

    If you select this check box, the search is case sensitive and the Search & Replace tool finds only text matching the search pattern exactly.

  • Replace with

    Specify the text to replace the text found when you select any of the Replace buttons (Replace, Replace all, Replace all in this object). See Use Replace Buttons.

  • Preserve case

    This option modifies replacement text. For an understanding of this option, see Replacing with Case Preservation.

  • Search in

    By default, the Search & Replace tool searches for and replaces text only within the current Stateflow® chart that you are editing in the Stateflow Editor. You can select to search the machine owning the current Stateflow chart or any other loaded machine or chart by accessing this selection box.

  • Match options

    This field is unlabeled and just to the right of the Search in field. You can modify the meaning of your search text by entering one of the selectable search options. See Refine Searches.

  • Object types and Field types

    Under the Search in field are the selection boxes for Object types and Field types. These selections further refine your search and are described below.

  • Search and Replace buttons

    These are described in Use the Search Button and View Area and Use Replace Buttons.

  • View Area

    The bottom half of the Search & Replace dialog box displays the result of a search. This area is described in A Breakdown of the View Area.

Refine Searches

Enter search pattern text in the Search for text box. You can use one of the following settings to further refine the meaning of the text entered.

Match case

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 with the same sequence of base characters in lower- or uppercase. For example, the search entry"AnDrEw" finds the matching text "andrew" or "Andrew" or "ANDREW".

Preserve case

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

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 that you have a state with this label and entry action:

throt_fail
entry: fail_state[THROT] = 1;

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

Match whole word

Select this option to specify that the search pattern 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 fail finds no text within that state. However, searching for "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 text composed of letters, numbers, and special symbols that defines one or more 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 "fail_" matches the "fail_" text that is part of the second line, character for character. Searching with the regular expression "\w*_" also finds the text "fail_". This search 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 (MATLAB).

Specify 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 chart for searching in the Search in field. By default, the current chart in which you opened 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 by deselecting one or more object types.

Note

You cannot search in state transition tables with this tool.

Field Types

Limit your search by deselecting 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.

Note

The Name field of machines and charts is an invalid target for the Search & Replace tool. Use the Simulink® model window to change the names of machines and charts.

Labels.  Only states and transitions have labels.

Descriptions.  All objects have searchable Description fields.

Document links.  All objects have searchable Link fields.

Use 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 appear 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 View 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.

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.

Specify 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 selected the Preserve case option.

Replacing with Case Preservation

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

  • Whisper

    Matching text has only lowercase characters. Matching text is replaced entirely with the lowercase equivalent of all replacement characters. For example, if the replacement text is "ANDREW", the matching text "bill" is replaced by "andrew".

  • Shout

    Matching text has only uppercase characters. Matching text is replaced entirely with the uppercase equivalent of all replacement characters. For example, if the replacement text is "Andrew", the matching text "BILL" is replaced by "ANDREW".

  • Proper

    Matching text has uppercase characters in the first character position of each word. Matching text is replaced entirely with the case equivalent of all replacement characters. For example, if the replacement text is "andrew johnson", the matching text "Bill Monroe" is replaced by "Andrew Johnson".

  • Sentence

    Matching text has an uppercase character in the first character position of a sentence with all other sentence characters in lowercase. Matching text is replaced in like manner, with the first character of the sentence given an uppercase equivalent and all other sentence characters set to lowercase. For example, if the replacement text is "andrew is tall.", the matching text "Bill is tall." is replaced by "Andrew is tall.".

If the matching text does not follow any of these patterns, then the text and case replacement match the user input.

Use 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 in the Search for field is replaced by the text you entered in the Replace with field. The Search & Replace tool then searches for the next occurrence of the Search for text.

Replace all

When you select the Replace all button, all instances of text matching the Search for field are replaced by the text 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.

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 search text 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.

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.