Discussion:
SImulink - Display block and Embedded Matlab Function Block
(too old to reply)
st
2011-01-31 05:42:03 UTC
Permalink
Hi all,

I am trying to output a string data (eg: Low, Moderate, High) to display block.

But i got error of

Character outputs are not supported in Simulink and Stateflow. Cast 'y' to int8 or uint8 instead.

May i know it is NOT possible to display string on Display Block?
If it is so... how should i output my value from Embedded Matlab Block to Command Window?

Thanks.
Paulo Silva
2011-01-31 06:17:03 UTC
Permalink
Post by st
Hi all,
I am trying to output a string data (eg: Low, Moderate, High) to display block.
But i got error of
Character outputs are not supported in Simulink and Stateflow. Cast 'y' to int8 or uint8 instead.
May i know it is NOT possible to display string on Display Block?
If it is so... how should i output my value from Embedded Matlab Block to Command Window?
Thanks.
I tried without much success inside the embedded matlab block but you might find a way, instead of the display block use one of the blocks that shows a string like the To Workspace, where's how you change the string
set_param('ModelName\To Workspace','VariableName','Moderate')
Paulo Silva
2011-01-31 10:42:03 UTC
Permalink
I managed to find a way to do it, not perfect but it works, put a display in your model, go to the display Block Properties, in the tab Block notation select the Tag to be shown in the annotation, now here's how to change the Tag and also the color of the display with the input:

function y = fcn(u)
% This block supports the Embedded MATLAB subset.
% See the help menu for details.
eml.extrinsic('set_param');
if (u>=0.6)
set_param('pj1/Display','Tag','High')
set_param('pj1/Display','BackgroundColor','[1 0 0]')
elseif (u>0.4)
set_param('pj1/Display','Tag','Average')
set_param('pj1/Display','BackgroundColor','[1 1 0]')
else
set_param('pj1/Display','Tag','Low')
set_param('pj1/Display','BackgroundColor','[0 1 0]')
end
y = u;


pj1 was the name of the model.
Paulo Silva
2011-01-31 10:50:06 UTC
Permalink
you can also change the font size and hide the block name (click the block and go to Format menu of simulink, click on hide name)
Paulo Silva
2011-01-31 12:38:04 UTC
Permalink
Display the text inside the embedded function block!!

function y = fcn(u)
% This block supports the Embedded MATLAB subset.
% See the help menu for details.
eml.extrinsic('set_param');
if (u>=0.6)
set_param('pj1/Embedded MATLAB Function','BackgroundColor','[1 0 0]')
set_param('pj1/Embedded MATLAB Function','MaskDisplay', ['disp(' char(39) 'High' char(39) ');'])
elseif (u>0.4)
set_param('pj1/Embedded MATLAB Function','BackgroundColor','[1 1 0]')
set_param('pj1/Embedded MATLAB Function','MaskDisplay',['disp(' char(39) 'Average' char(39) ');'])
else
set_param('pj1/Embedded MATLAB Function','BackgroundColor','[0 1 0]')
set_param('pj1/Embedded MATLAB Function','MaskDisplay',['disp(' char(39) 'low' char(39) ');'])
end
y = u;

Loading...