Why am I unable to use a carriage return or line feed character in my FPRINTF statement in Stateflow?

2 views (last 30 days)
If I have the following typed into an arbitrary state, within my Stateflow diagram:
Welcome_message /
ml('fprintf(''Welcome to stateflow\n'')');
ml('fprintf(''Goodbye from stateflow'')');%
and then run the simulation, I get the following error message:
Welcome to stateflow??? fprintf('
|
Missing ' at end of string or misplaced transpose operator.
However, when I type the same fprintf line in MATLAB, I get the correct results.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is the expected behavior of Stateflow. The carriage return escape character '\' is a valid character in the Stateflow action language and does get interpreted.
In this particular example you need to pass the '\' symbol un-interpreted to the MATLAB FPRINTF function. Thus you need to escape the '\\' char using double '\\' as follows:
ml('fprintf(''Welcome to stateflow\\\'')');
A better way of re-doing the whole thing is to use the MATLAB name space mechanism in the Stateflow action language as follows:
Welcome_message/
ml.fprintf('Welcome to stateflow\');
ml.fprintf('Goodbye from stateflow');
Please note that since the name space is explicit we no longer need to escape the '\\' character.

More Answers (0)

Categories

Find more on Complex Logic in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!