Customize MATLAB System Block Appearance
This example shows how to customize the appearance of the MATLAB System block.
System objects allow you to implement algorithms using MATLAB. System objects are a specialized kind of MATLAB object, designed specifically for implementing and simulating dynamic systems with inputs that change over time.
After you define a System object, you can include it in a Simulink model using a MATLAB System block.
There are three MATLAB System blocks in this model. The first block does not have any customization for block appearance and by default shows the name of the System object on the block. The port labels for this block are obtained from the name of the arguments in the
stepImpl method of the System object. Second block shows custom text and custom port labels on the block icon. The third block shows a custom block icon image.
System Object Class Definition
You can access MATLAB source code used by the MATLAB System block by clicking the "Source Code" hyperlink from the block dialog. The
TimesTwo System object used in the first block has no customization and implements only the
stepImpl method. The
CustomBlockIconExample System object implements the following methods for customizing block appearance.
getInputNamesImpl- Customize input port labels
getOutputNamesImpl- Customize output port labels
getIconImpl- Display text or an image on the block
The System object has a
DisplayImage property to choose between text and image for display on the block.
TimesTwo System object
classdef TimesTwo < matlab.System %TimesTwo Multiply input by 2 % obj = TimesTwo returns a System object, obj, that % multiples its input by two. methods(Access = protected) function y = stepImpl(~, u) y = 2 * u; end end end
CustomBlockIconExample System object
classdef CustomBlockIconExample < matlab.System % SystemObjectBlockIconExample Customize Block Icon properties(Nontunable) % DisplayImage Select to display image as block icon DisplayImage (1,1) logical = false end methods(Access = protected) function y = stepImpl(~, u) y = u; end function inputName = getInputNamesImpl(~) inputName = "MyIn"; end function outputName = getOutputNamesImpl(~) outputName = "MyOut"; end function icon = getIconImpl(obj) % Return text or image to be displayed on the block icon % Use array of strings to display multiple lines of text if obj.DisplayImage % Display image icon = matlab.system.display.Icon('slexngc6543aPix.jpg'); else % Display text icon = ["Block icon", "with custom text"]; end end end end