| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Stateflow |
| Contents | Index |
| Learn more about Stateflow |
| On this page… |
|---|
Opening the Search & Replace Tool Using the Search Button and View Area |
To open the Search & Replace dialog box:
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:
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).
If you select this check box, the search is case sensitive and the Search & Replace tool finds only text matching the search pattern exactly. See Match case (Case Sensitive).
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 Using the Replace Buttons.
This option modifies replacement text. For an understanding of this option, see Replacing with Case Preservation.
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.
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 Using Different Search 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. By default, these boxes are hidden. Only current selections appear next to their titles.
Select the right-facing arrow button
in front
of the title to expand a selection box and make changes.
Select the same button (this time with a left-facing arrow)
to compress
the selection box to display the settings only, or, if you want, just
leave the box expanded.
These are described in Using the Search Button and View Area and Using the Replace Buttons.
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.
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.
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.
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".
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.
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.
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.
This option modifies replacement text and not search text. For details, see Replacing with Case Preservation.
You specify the scope of your search by selecting from the field regions discussed in the topics that follow.
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:
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.
To select a Stateflow chart for searching, follow these steps:
Select the down arrow of the Search in field again.
This list contains the previously selected machine expanded to reveal its Stateflow charts.
Limit your search to text matches in the selected object types by following these steps:
Limit your search to text matches for the specified fields by following these steps:
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.
Custom code. Only target objects contain custom code.
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.

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.
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.
Right-click anywhere in the Search & Replace dialog box to display a menu with these selections.
Selection | Result |
|---|---|
A toggle switch that hides or displays the portal. | |
Displays the object with matching text in the Stateflow Editor. Applies to states, junctions, transitions, and charts. | |
Displays the object with matching text in the Model Explorer. Applies to states, data, events, machines, charts, and targets. | |
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.
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.
If you choose the Case Preservation 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.".
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.
You can activate the replace buttons (Replace, Replace All, Replace All in This Object) only after a search that finds text.
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.
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.
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.
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:
A search was attempted without a search string specified.
No matches exist in the selected search scope.
No more matches exist in the selected search scope.
The following warnings refer to invalid conditions for searching or replacing:
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.
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.
If you search for text, find it, and then delete the containing object, this warning appears if you continue to search.
If you search for text, find it, and then delete the containing object, this warning appears if you perform a replacement.
If you search for text, find it, and then change the object containing the text, this warning appears if you perform a replacement.
If you search for text, find it, and then change the Search For field, this warning appears if you perform a replacement.
![]() | Using the Model Explorer with Stateflow Objects | Finding Stateflow Objects | ![]() |

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 |