System object tunable parameters
조회 수: 8 (최근 30일)
이전 댓글 표시
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
% CreateTruthStruct: This is the system object that will generate the
% TruthStates bus from EOM outputs.
% Public, tunable properties
properties
Truth = struct();
end
end
댓글 수: 0
채택된 답변
Anay
2025년 2월 7일
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.
추가 답변 (1개)
Abhishek
2025년 2월 7일
편집: Abhishek
2025년 2월 7일
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:
- 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.
- 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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Create System Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!