How can I toggle the visibility of a matlab property based on
조회 수: 7 (최근 30일)
이전 댓글 표시
Refering to the example on the link provided, it programmatically define tabs and group for the block GUI. I would like some of those tabs / sections to be visible or invisible depending on an action performed. For example, if First initial condition = 0, I'd like to hide second and third initial condition. If the check box for threshold is unchecked, Threshold property is not visible.
Lastly, I would like to remove the source code link (and text). How can I program it to be hidden?
Looking forward to some feedback, suggestions.
댓글 수: 0
채택된 답변
Epsilon
2025년 8월 11일
Hi Wilfried,
To dynamically control which properties appear in a MATLAB System block dialog, override the isInactivePropertyImpl method in your System object class. This approach lets you show or hide properties based on the values of other properties at runtime.
In the example below, the SecondIC and ThirdIC properties are hidden when FirstIC is set to zero. The Threshold property is only visible if UseThreshold is checked. To update the dialog after changing parameter values, click "Apply" or close and reopen the dialog box.
classdef sampleScript < matlab.System
% sample script for dialog demo
properties(Nontunable)
FirstIC (1,1) double = 0
SecondIC (1,1) double = 0
ThirdIC (1,1) double = 0
UseThreshold (1,1) logical = false
Threshold (1,1) double = 1
end
methods (Access = protected)
function group = getPropertyGroupImpl(obj)
group = matlab.system.display.Section(...
'Title', 'Filter Settings', ...
'PropertyList', {'FirstIC', 'SecondIC', 'ThirdIC', 'UseThreshold', 'Threshold'});
end
function flag = isInactivePropertyImpl(obj, prop)
if ismember(prop, {'SecondIC', 'ThirdIC'})
flag = obj.FirstIC == 0;
elseif strcmp(prop, 'Threshold')
flag = ~obj.UseThreshold;
else
flag = false;
end
end
end
end
In recent releases the "Source code" link cannot be toggled. As a workaround, wrap your MATLAB System block in a masked subsystem and use the Mask Editor to control which parameters are visible. The subsystem dialog will not show the "Source code" link.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!