Questions related to MATLAB App

7 views (last 30 days)
Devesh
Devesh on 14 Feb 2024
Answered: Samay Sagar on 23 Sep 2024
Will “setparam” in the app code work for standalone apps (on a PC that does not have MATLAB, just has the Runtime)? If yes, what is the correct way to use it - I tried connecting to a toggle switch value change as below:
--> setparam(tg,'Constant Block Name','Value',1); where tg=slrealtime(app.TargetSelector.TargetName);
I am getting below error:
Unable to set 'Value' parameter value on target computer 'TargetPC1': Unable to tune parameter 'Value'. This
parameter is an expression containing workspace variables. Tune the workspace variables. Can someone please help!
Some more questions related to app designer:
  1. How can we customize the x-axis of the instrumented axes in MATLAB App (with model running on Speedgoat)? I wanted to plot Speed vs Torque (signals from Simulink model) (in the axes) instead of separately plotting them with respect to time.
  2. How to connect MATLAB app fields (which need double data) to a constant block with Boolean/enum datatype in the Simulink model?
  3. Is the signal logging (in the Simulink model) necessary to read/instrument the signals in app?
  4. Is there a way to send a dataset input to Simulink model from the app (like if we upload xlsx/mat file and send the data to constant block in the Simulink mode one sample at a time)? Right now, I can send the path of the file from the app to the “From File” block in the Simulink and that can handle the job, was just wondering if there is a better way.
Any help is greatly appreciated. Thanks!

Answers (1)

Samay Sagar
Samay Sagar on 23 Sep 2024
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:
%Assuming speed and torque are your acquired data vectors
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); % Convert to logical type
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:

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!