Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

String signals in simulink with switches?

901 views
Skip to first unread message

Stefan Larsson

unread,
Sep 24, 2008, 2:10:03 AM9/24/08
to
I am curious whether anyone has some ide on how to solve the following problem:

Assume that a block receives integer numbers which can be seen as a x-axis. The "y-axis" returns strings which then are used to select output from a bunch of lookup tables.

The problem here is:
1. how to send strings as signals?
2. how to make a switch which is taking strings as input?

The reason for doing this? I am importing data from a proprietary system and do not want to map such constant strings into numbers since it would be difficult to make that robust. The code I am emulating is probably written in C using #define statements.

Regards,
Stefan Larsson

checker

unread,
Sep 24, 2008, 4:28:38 PM9/24/08
to
On Sep 23, 11:10 pm, "Stefan Larsson"

This solution answers your questions, but certainly isn't what you're
looking for. Simulink doesn't handle strings as a datatype for
signals. Still, maybe this will give you some additional insite to
the tools and the problem.

-Chris
0) create the 2 user defined functions below
1)add a constant source w/value of 1
2)using above as input, add a user defined matlab function w/function
name: sendstr
3)using above as input, add a user defined matlab function w/funciton
name: switchstr
4)using above as input, add a display block

function y=sendstr(u)
if u == 1
y = 'one ';
elseif u == 2
y = 'two ';
elseif u == 3
y = 'three';
else
y = 'zero';
end
y=abs(y);

function y=switchstr(u)
u=char(u)'
if strcmp(u,'one ')
y = 1;
elseif strcmp(u,'two ')
y = 2;
elseif strcmp(u,'three')
y = 3;
else
y = 0;
end

Ralph Schleicher

unread,
Sep 25, 2008, 3:59:57 PM9/25/08
to
"Stefan Larsson" <lastsys.r...@remove.this.gmail.com> writes:

> The problem here is: 1. how to send strings as signals?

Use a uint8 vector signal.

> 2. how to make a switch which is taking strings as input?

Use the same length for all strings (i.e. uint8 vector signals),
pad shorter strings with zeros.

--
Ralph Schleicher <http://ralph-schleicher.de>

Development * Consulting * Training
Mathematical Modeling and Simulation
Software Tools

0 new messages