1. Using "setparam" in a standalone app (with MATLAB Runtime)
When using "setparam" in a standalone app, it should work if you have correctly deployed the app with the necessary Simulink Real-Time (SLRT) components included. The error you are seeing is because the parameter you are trying to tune (Value of the "Constant block") is likely linked to a workspace variable, which needs to be updated instead of the block parameter itself.
Ensure that the parameter being tuned is not dependent on workspace variables or update the workspace variable directly via the app. For example, if the "Constant block" refers to a variable in the base workspace, you should update the workspace variable rather than the block parameter directly.
setparam(tg, 'Constant Block Name', 'Value', evalin('base', 'workspace_variable'));
2. Customizing the x-axis in App Designer (Speed vs Torque)
To plot Speed vs Torque on the x and y axes instead of plotting against time:
- Use "scatter" or "plot" to plot custom x-y relationships: When fetching real-time data from the Speedgoat target, ensure you are acquiring both the Speed and Torque signals simultaneously. You can then update the "UIAxes" object with a custom plot:
plot(app.UIAxes, speed, torque);
xlabel(app.UIAxes, 'Speed');
ylabel(app.UIAxes, 'Torque');
- You can set the "UIAxes" limits, labels, and other properties through the app code as needed.
3. Connecting App Fields to Simulink Blocks with Different Data Types
To connect a MATLAB App field (like a double value) to a Simulink block that expects a Boolean or enum type:
- Type Casting:You need to ensure type consistency when interacting with Simulink. For a Boolean or enum, use MATLAB’s type-casting functions like "logical" or "enumeration":
- For Boolean blocks:
boolVal = logical(app.DoubleField.Value);
setparam(tg, 'BlockName', 'ParameterName', boolVal);
- For enum values, ensure your Simulink block is set up to use the correct enum class, then cast accordingly:
numVal = enumeration('YourEnumClass', app.DoubleField.Value);
setparam(tg, 'BlockName', 'ParameterName', enumVal);
4. Is signal logging necessary for instrumentation in the app?
No, signal logging is not strictly necessary to instrument signals in the app. You can use:
- Simulink Real-Time (SLRT) API: Use "tg.getsignal" to directly read real-time signals from the target and plot or display them in the app. This approach does not require logging but allows you to monitor signals dynamically.Example:
signalValue = tg.getsignal('SignalName');
Signal logging can be useful for post-processing or analyzing data after the simulation, but real-time monitoring should be sufficient for most interactive app purposes.
5. Sending a dataset input to Simulink from the app
If you wish to send a dataset (e.g., from an Excel or MAT file) to Simulink, there are a couple of approaches:
For more information, you can refer the following documentations: