Main Content

Use the Search and Replace Tool

To open the Search & Replace dialog box:

  1. Open a chart.

  2. In the Modeling tab, select Find > Find & Replace in Chart.

Search for

In the Search for field, enter search pattern text. You can select the interpretation of the search pattern with the Match case check box and the Match options field, which is unlabeled and just to the right of the Search in field.

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".

Replace with

Specify the text to replace the text found when you select any of the Replace buttons.

ButtonDescription
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.

Preserve case

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

ConditionDescription
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".

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".

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".

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.

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.

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.

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:

Match OptionDescription
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 (_).

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.

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.

Object types

Limit your search by deselecting one or more object types.

Field types

Under the Search in field are the selection boxes for Field types.You can limit your search by clearing one or more field types.

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.

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

States and transitions have labels that you can use the search tool to find.

Descriptions

All objects have searchable Description fields.

Document links

All objects have searchable Document Link fields.

Viewing Search Results

Click Search to begin your search. 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.

View Area

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

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

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 searched downward from parent to child until an object with no child is encountered. At this point, the search begins again at an unsearched sibling is found and the process repeats.

Related Topics