System object tunable parameters

3 views (last 30 days)
KnightHawk
KnightHawk on 5 Feb 2025
Commented: KnightHawk on 8 Feb 2025
I have a matlab system object where Truth is a tunable property (it's a struct containing only numeric params) but I'm getting the error below which is causing the Simulink model to recompile each time, what can I do here to keep Truth as tunable and avoid recompiling? Truth will change from run to run so it needs to be tunable.
Warning: The System object 'CreateTruthStruct' specified in the MATLAB System block 'UAV Dynamics/Quadcopter Model/MATLAB System1' has a property 'Truth' defined as tunable. It was set as a non-tunable parameter in the block to work in Simulink. Simulink does not allow parameters whose values are booleans, literal character vectors, string objects or non-numeric structures to be tunable.
classdef CreateTruthStruct < matlab.System
Class name and filename must match.
% CreateTruthStruct: This is the system object that will generate the
% TruthStates bus from EOM outputs.
% Public, tunable properties
properties
Truth = struct();
end
end

Accepted Answer

Anay
Anay on 7 Feb 2025
Hi KnightHawk,
I faced the same error when I tried to replicate the problem you described. I found that if you provide a default value for the parameter “Truth” you can have it as a tunable parameter.
You can refer to the following example to give a default value to the parameter:
Truth (1,1) struct = struct('field1', 1, 'field2', 2)
Hope this solves the problem.

More Answers (1)

Abhishek
Abhishek on 7 Feb 2025
Edited: Abhishek on 7 Feb 2025
Hi,
The issue you're experiencing with your MATLAB System object is likely due to a mismatch between the class name and the filename. In MATLAB, it's essential that the class name matches the filename exactly. This mismatch can lead to errors and unexpected behavior, such as the warning you're seeing about the ‘Truth’ property causing recompilation in Simulink.
To resolve this issue, please follow these steps:
  1. Double-check that the filename of your MATLAB System object is the same as the class name. For instance, if your class is defined as‘CreateTruthStruct, the file should be named‘CreateTruthStruct.m’. This alignment is crucial for MATLAB to correctly recognize and compile the class.
  2. Ensure that the directory containing your ‘CreateTruthStruct.m’ file is included in the MATLAB path. You can add the directory using the ‘addpath’ function or by going to Home > Set Path in MATLAB. Please refer the documentation for more information: - https://www.mathworks.com/help/releases/R2023b/matlab/ref/addpath.html
Hope this helps to solve the problem. Thanks.

Categories

Find more on Create System Objects in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!