| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → xPC Target |
| Contents | Index |
| Learn more about xPC Target |
By default, the xPC Target software lets you change parameters in your target application while it is running in real time.
You can also improve overall efficiency by inlining parameters. The xPC Target product supports the Real-Time Workshop® inline parameters functionality (see the Real-Time Workshop documentation for further details on inlined parameters). By default, this functionality makes all parameters nontunable. If you want to make some of the inlined parameters tunable, you can do so through the Model Parameter Configuration dialog box (see Inlined Parameters).
Note Opening a dialog box for a source block causes Simulink to pause. While Simulink is paused, you can edit the parameter values. You must close the dialog box to have the changes take effect and allow Simulink to continue. |
The xPC Target software lets you change parameters in your target application while it is running in real time. With these functions, you do not need to set the Simulink interface to external mode, and you do not need to connect the Simulink interface with the target application.
You can download parameters to the target application while it is running or between runs. This feature lets you change parameters in your target application without rebuilding the Simulink model. You cannot use xPC Target Explorer to change tunable source block parameters while a simulation is running.
After you download a target application to the target PC, you can change block parameters using xPC Target Explorer. This procedure uses the Simulink model xpcosc.mdl as an example, and assumes you have created and downloaded the target application for that model.
In xPC Target Explorer, right-click the downloaded target application node. For example, xpcosc.
To get the list of parameters in the target application, expand the Model Hierarchy node under the target application.
The Model Hierarchy expands to show the elements in the Simulink model.

The model hierarchy shows only those blocks that have tunable parameters.
Select the parameter of the signal you want to edit. For example, select Gain.
The right pane displays the block parameters dialog box for Gain. There is one parameter, Gain, for this block. The current value of the Gain parameter is displayed.
Double-click the box that contains the gain value.
The box becomes editable.
The box is updated and the Update Parameter button becomes active.

If there is a scope, the plot frame then updates the signals after running the simulation with the new parameter value.
Stop the target application. For example, to stop the target application xpcosc, right-click it and select Stop.
The target application on the target PC stops running.
You use the MATLAB functions to change block parameters. With these functions, you do not need to set the Simulink interface to external mode, and you do not need to connect the Simulink interface with the target application.
You can download parameters to the target application while it is running or between runs. This feature lets you change parameters in your target application without rebuilding the Simulink model.
After you download a target application to the target PC, you can change block parameters using xPC Target functions. This procedure uses the Simulink model xpcosc.mdl as an example, and assumes you have created and downloaded the target application for that model. It also assumes that you have assigned tg to the appropriate target PC.
+tg
or
tg.start
or
start(tg)
The target PC displays the following message:
System: execution started (sample time: 0.001000)
Display a list of parameters. Type either
set(tg,'ShowParameters','on')
or
tg.ShowParameters='on'
The latter command displays a list of properties for the target object.
ShowParameters = on
Parameters =
INDEX | VALUE | TYPE | SIZE | PARAMETER NAME | BLOCK NAME |
0 | 1000000 | DOUBLE | Scalar | Gain | Gain |
1 | 400 | DOUBLE | Scalar | Gain | Gain1 |
2 | 1000000 | DOUBLE | Scalar | Gain | Gain2 |
3 | 0 | DOUBLE | Scalar | Initial Condition | Integrator |
4 | 0 | DOUBLE | Scalar | Initial Condition | Integrator1 |
5 | 4 | DOUBLE | Scalar | Amplitude | Signal Generator |
6 | 20 | DOUBLE | Scalar | Frequency | Signal Generator |
Change the gain. For example, to change the Gain1 block, type either
tg.setparam(1,800)
or
setparam(tg,1,800)
As soon as you change parameters, the changed parameters in the target object are downloaded to the target application. The host PC displays the following message:
ans = parIndexVec: 1 OldValues: 400 NewValues: 800
If there is a scope, the plot frame then updates the signals after running the simulation with the new parameters.
Stop the target application. In the MATLAB window, type
-tg
or
tg.stop
or
stop(tg)
The target application on the target PC stops running, and the target PC displays messages like the following:
minimal TET: 0.000023 at time 1313.789000 maximal TET: 0.000034 at time 407.956000
Note Method names are case sensitive and need to be complete, but property names are not case sensitive and need not be complete as long as they are unique. |
You can reset parameters to preceding target object property values by using xPC Target methods on the host PC. The setparam method returns a structure that stores the parameter index, the previous value, and the new value. If you expect to want to reset parameter values, set the setparam method to a variable. This variable points to a structure that stores the parameter index and the old and new parameter values for it.
pt=tg.setparam(1,800)
The setparam method returns a result like
pt = parIndexVec: 1 OldValues: 400 NewValues: 800
To reset to the previous values, type
setparam(tg,pt.parIndexVec,pt.OldValues) ans = parIndexVec: 5 OldValues: 800 NewValues: 100
You use Simulink external mode to connect your Simulink block diagram to your target application. The block diagram becomes a graphical user interface to your target application. You set up the Simulink interface in external mode to establish a communication channel between your Simulink block window and your target application.
In Simulink external mode, wherever you change parameters in the Simulink block diagram, the Simulink software downloads those parameters to the target application while it is running. This feature lets you change parameters in your program without rebuilding the Simulink model to create a new target application.
Note Opening a dialog box for a source block causes Simulink to pause. While Simulink is paused, you can edit the parameter values. You must close the dialog box to have the changes take effect and allow Simulink to continue. |
After you download your target application to the target PC, you can connect your Simulink model to the target application. This procedure uses the Simulink model xpcosc.mdl as an example, and assumes you have created and downloaded the target application for that model.
In the Simulink window, and from the Simulation menu, click External.
A check mark appears next to the menu item External, and Simulink external mode is activated.
In the Simulink block window, and from the Simulation menu, click Connect to target.
All of the current Simulink model parameters are downloaded to your target application. This downloading guarantees the consistency of the parameters between the host model and the target application.
From the Simulation menu, click Start Real-Time Code, or, in the MATLAB window, type
+tg
or
tg.start
or
start(tg)
The target application begins running on the target PC, and the target PC displays the following message:
System: execution started (sample time: 0.000250)
From the Simulation block diagram, double-click the block labeled Gain1.
The Block Parameters: Gain1 parameter dialog box opens.

In the Gain text box, enter 800 and click OK.
As soon as you change a model parameter and click OK, or you click the Apply button on the Block Parameters: Gain1 dialog box, all the changed parameters in the model are downloaded to the target application.
From the Simulation menu, click Disconnect from Target.
The Simulink model is disconnected from the target application. Now, if you change a block parameter in the Simulink model, there is no effect on the target application. Connecting and disconnecting the Simulink interface works regardless of whether the target application is running or not.
In the MATLAB window, type either
stop(tg)
or
-tg
The target application on the target PC stops running, and the target PC displays the following messages:
minimal TET: 0.000023 at time 1313.789000 maximal TET: 0.000034 at time 407.956000
The Parameters pane displays a list of all the tunable parameters in your model. Row and column indices for vector/matrix parameters are also shown.
After you connect a Web browser to the target PC, you can use the Parameters page to change parameters in your target application while it is running in real time:
In the left frame, click the Parameters button.
The browser loads the Parameter List pane into the right frame.
If the parameter is a scalar parameter, the current parameter value is shown in a box that you can edit.
If the parameter is a vector or matrix, there is a button that takes you to another page that displays the vector or matrix (in the correct shape) and enables you to edit the parameter.
Enter a new parameter value into one or more of the parameter boxes, and then click the Apply button.
The new parameter values are uploaded to the target application.
After you have a set of target application parameter values that you are satisfied with, you can save those values to a file on the target PC. You can then later reload these saved parameter values to the same target application. You can save parameters from your target application while the target application is running or between runs. This feature lets you save and restore parameters in your target application without rebuilding the Simulink model. You save and restore parameters with the target object methods saveparamset and loadparamset.
The procedures assume that
You have a target application object named tg.
You have assigned tg to the appropriate target PC.
You have a target application downloaded on the target PC.
You have parameters you would like to save for reuse. See
To save a set of parameters to a target application, use the saveparamset method. The target application can be stopped or running.
Select a descriptive filename to contain these values. For example, use the model name in the filename. You can only load parameter values to the same target application from which you saved the parameter values.
In the MATLAB window, type either
tg.saveparamset('xpc_osc4_param1') or
saveparamset(tg,'xpc_osc4_param1')
The xPC Target software creates a file named xpcosc4_param1 in the current folder of the target PC, for example, C:\xpcosc4_param1.
For a description of how to restore parameter values to a target application, see Loading Saved Parameters to a Target Application. For a description of how to list the parameters and values stored in the parameter file, see Listing the Values of the Parameters Stored in a File.
To load a set of saved parameters to a target application, use the loadparamset method. You must load parameters to the same model from which you save the parameter file. If you load a parameter file to a different model, the behavior is undefined.
This section assumes that you have a parameters file saved from an earlier run of saveparamset (see Saving the Current Set of Target Application Parameters).
From the collection of parameter value files on the target PC, select the one that contains the parameter values you want to load.
In the MATLAB window, type either
tg.loadparamset('xpc_osc4_param1') or
loadparamset(tg,'xpc_osc4_param1')
The xPC Target software loads the parameter values into the target application.
For a description of how to list the parameters and values stored in the parameter file, see Listing the Values of the Parameters Stored in a File.
To list the parameters and their values, load the file for a target application, then turn on the ShowParameters target object property.
This section assumes that you have a parameters file saved from an earlier run of saveparamset (see Saving the Current Set of Target Application Parameters).
Ensure that the target application is stopped. For example, type
tg.stop
Load the parameter file. For example, type
tg.loadparamset('xpc_osc4_param1');Display a list of parameters. For example, type
tg.ShowParameters='on';
and then type
tg
The MATLAB window displays a list of parameters and their values for the target object.
This procedure describes how you can globally inline parameters for a model, then specify which of these parameters you still want to be tunable. It assumes that you are familiar with how to build target applications (if you are not, read the xPC Target Getting Started Guide first). After you have performed this procedure, you will able to tune these parameters.
The following procedure uses the Simulink model xpcosc.mdl as an example.
In the MATLAB Command Window, type
xpcosc
The model is displayed in the Simulink window.
Select the blocks of the parameters you want to make tunable. For example, this procedure makes the signal generator's amplitude parameter tunable. Use the variable A to represent the amplitude.
Double-click the Signal Generator block and enter A for the Amplitude parameter. Click OK.
In the MATLAB Command Window, assign a constant to that variable. For example, type
A = 4
The value is displayed in the MATLAB workspace.
In the Simulink window, from the Simulation menu, click Configuration Parameters.
The Configuration Parameters dialog box for the model is displayed.
In the rightmost pane, select the Inline parameters check box.
The Configure button is enabled.
The Model Parameter Configuration dialog box is displayed. Note that the MATLAB workspace contains the constant you assigned to A.
Select the line that contains your constant and click Add to table.
The Model Parameter Configuration dialog box appears as follows.

If you have more global parameters you want to be able to tune, add them also.
In the Configuration Parameters dialog, click Apply, then OK.
If you want, increase the model stop time, or set it to inf.
When you are finished, click Apply, then OK, and save the model. For example, save it as xpc_osc5.mdl.
You next can use xPC Target Explorer or the MATLAB interface to work with the tunable parameters.
This procedure describes how you can tune inlined parameters through the xPC Target Explorer. It assumes that you have built and downloaded the model from the topic Inlined Parameters to the target PC. It also assumes that the model is running.
If you have not yet started xPC Target Explorer, do so now. Be sure it is connected to the target PC to which you downloaded the xpc_osc5 target application.
To get the list of tunable inlined parameters in the target application, expand the target application node, then expand the Model Hierarchy node under the target application node.

Note that the Model Hierarchy node displays a list of signals and an object called Model Parameters. Model Parameters contains the list of tunable inlined parameters.
To display the tunable parameters, select Model Parameters.
The constant A and its value are shown in the right pane.
Double-click the box that contains the tunable parameter A.
The box becomes editable.
Enter a new value for the parameter and press Enter.
The box is updated and the Update Parameter button becomes active.

To verify the updated value, select the signal object associated with A. For example, select Signal Generator.
The value of Signal Generator is shown in the right pane.

This procedure describes how you can tune inlined parameters through the MATLAB interface. It assumes that you have built and downloaded the model from the topic Inlined Parameters to the target PC. It also assumes that the model is running.
You can tune inlined parameters using a parameter ID as you would conventional parameters.
Use the getparamid function to get the ID of the inlined parameter you want to tune. For the block_name parameter, leave a blank ('').
Use the setparam function to set the new value for the inlined parameter.
Save the following code in an M-file. For example, change_inlineA.
tg=xpc; %Create xPC Target object
pid=tg.getparamid('','A'); %Get parameter ID of A
if isempty(pid) %Check value of pid.
error('Could not find A');
end
tg.setparam(pid,100); %If pid is valid, set parameter value.Execute that M-file. For example, type
change_inlineA
To see the new parameter value, type
tg.showparameters='on'
The tg object information is displayed, including the parameter lines:
NumParameters = 1
ShowParameters = on
Parameters = INDEX VALUE TYPE SIZE PARAMETER NAME BLOCK NAME
0 100 DOUBLE Scalar A
![]() | Signal Logging | Booting from a DOS Device | ![]() |

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 |