f



SImulink - Display block and Embedded Matlab Function Block

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.
0
st
1/31/2011 5:42:03 AM
comp.soft-sys.matlab 211266 articles. 18 followers. lunamoonmoon (258) is leader. Post Follow

4 Replies
1696 Views

Similar Articles

[PageSpeed] 20

"st " <cell_st@hotmail.com> wrote in message <ii5i3b$iim$1@fred.mathworks.com>...
> 
> 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')
0
Paulo
1/31/2011 6:17:03 AM
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.
0
Paulo
1/31/2011 10:42:03 AM
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)
0
Paulo
1/31/2011 10:50:06 AM
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;
0
Paulo
1/31/2011 12:38:04 PM
Reply: