<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!-- generator="wordpress/2.3.1" --><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Seth on Simulink</title>
	<link>http://blogs.mathworks.com/seth</link>
	<description>This blog is about Simulink.</description>
	<pubDate>Wed, 18 Nov 2009 15:05:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/SethOnSimulink" type="application/rss+xml" /><feedburner:emailServiceId>SethOnSimulink</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Back-Seat Driver: Simulink Tips for Efficient Model Navigation</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/dt5NZIHM-Sc/</link>
		<comments>http://blogs.mathworks.com/seth/2009/11/18/back-seat-driver-simulink-tips-for-efficient-model-navigation/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 03:45:50 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Simulink Tips]]></category>

		<category><![CDATA[Simulink navigation]]></category>

		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/11/18/back-seat-driver-simulink-tips-for-efficient-model-navigation/</guid>
		<description><![CDATA[Does this ever happen to you? You are sitting in a
meeting looking up at the projected image of your coworker’s computer desktop. 
They are navigating through {a web page, a Simulink model, or computer
settings}.  You can see a faster, better, more efficient way to complete the
task.  You as the observer have two options:  1) politely bite [...]]]></description>
			<content:encoded><![CDATA[<p><em>Does this ever happen to you? </em>You are sitting in a
meeting looking up at the projected image of your coworker’s computer desktop. 
They are navigating through {a web page, a Simulink model, or computer
settings}.  You can see a faster, better, more efficient way to complete the
task.  You as the observer have two options:  1) politely bite your lip or 2)
become the back-seat driver and scream out corrective commands like “up, up,
up... to the right, right, left... click the thing...open... control-k...arg!”</p>

<p>This happens to me some times... especially with Simulink
models.  I want to share with you two Simulink tips that I wish everyone knew.</p>

<p><strong>Tip: Navigating your model – window reuse, and escape.</strong></p>

<p>I spend much of my day looking at models I did not build. 
Finding your way around large models can be slow due to the many layers of
subsystems between the top of the model and the leaf component you are working
on.  There are two parts to this tip.</p>

<p><em>Part one is setting window reuse.</em>  Make sure the
model is set for window reuse.  I rarely need to look at two different systems
at the same time, so my preference is to set Simulink to reuse the windows as I
navigate the diagram.  A close alternative is to use mixed.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/simulinkPreferences.png" alt="Simulink Preferences control window reuse."></p>

<p>Part two is using the escape key.  Diving down through
layers of a model is as easy as double clicking on a subsystem.  What do you do
when you want to go back up a level?  While you can reach for the arrows on the
toolbar to go back, or up a level, I use the escape key.  Escape will bring you
to the level above the current level.  This even works if you have opened a
reference model, Stateflow chart, Embedded MATLAB function blocks and block
dialogs!</p>

<p><strong><img src="http://blogs.mathworks.com/images/seth/2009Q4/escNavigate.gif" alt="Annimation showing the easy navigation accross many levels of model hierarchy."></strong></p>

<p><strong>What do you know?</strong></p>

<p>What accelerators do you use to work more efficiently?  What
do you yell when back-seat driving? Leave a <a
href="http://blogs.mathworks.com/seth/?p=74&amp;#comment">comment here</a> and
tell me about it.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/dt5NZIHM-Sc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/11/18/back-seat-driver-simulink-tips-for-efficient-model-navigation/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/11/18/back-seat-driver-simulink-tips-for-efficient-model-navigation/</feedburner:origLink></item>
		<item>
		<title>Generated Code for Variable Size Signals</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/Yf71tJ0eEkk/</link>
		<comments>http://blogs.mathworks.com/seth/2009/11/06/generated-code-for-variable-size-signals/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 01:48:56 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Code Generation]]></category>

		<category><![CDATA[Signals]]></category>

		<category><![CDATA[What's new?]]></category>

		<category><![CDATA[Real-Time Workshop]]></category>

		<category><![CDATA[RTW]]></category>

		<category><![CDATA[Simulink]]></category>

		<category><![CDATA[variable dimensions]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/11/06/generated-code-for-variable-size-signals/</guid>
		<description><![CDATA[Aarti recently posted about Variable Size Signals in Simulink.  Han responded with this comment:


Aarti,

I would be interested in the effect on RTW generated code for variable size signals. Could you show some examples?

-Han


Here is Aarti's response.



Hi Han,

Thank you for your comment. In the case of a variable size signal, the generated code allocates the [...]]]></description>
			<content:encoded><![CDATA[<p>Aarti recently posted about <a href="http://blogs.mathworks.com/seth/2009/10/16/radar-tracking-in-simulink-variable-size-signals/">Variable Size Signals</a> in Simulink.  Han responded with <a href="http://blogs.mathworks.com/seth/2009/10/16/radar-tracking-in-simulink-variable-size-signals/#comments">this comment</a>:</p>

<blockquote>
Aarti,<br />

I would be interested in the effect on RTW generated code for variable size signals. Could you show some examples?<br />

-Han<br />
</blockquote>

<p>Here is Aarti's response.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/Aarti_Ramani.jpg" alt="Aarti Ramani"></p>

<p>Hi Han,</p>

<p>Thank you for your comment. In the case of a variable size signal, the generated code allocates the maximum possible size for the input/output variables. </p>

<p>This allows signal sizes to vary during execution (as opposed to being hard-coded after model compilation). The generated code also propagates signal sizes through the model and accordingly assign the required dimension to signals.  The algorithm code only needs to operate on the portion of memory required (thus saving execution time).</p>

<p>The following model uses the Switch Block to change the size of its output signal.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/varDim_SwitchGain.png" alt="Simulink model containing a Switch and Gain block that handles variable size signals." /></p>

<p>The generated code looks like this:</p>

<p><pre><code style="font-size: 11pt;">
  /* Switch: '<Root>/Switch' incorporates:
   *  Inport: '<Root>/In1'
   *  Inport: '<Root>/In2'
   *  Inport: '<Root>/In3'
   */
  if (In2 >= 0.0) {
    model_XDim = 1;
    X[0] = In1;
  } else {
    model_XDim = 5;
    for (tmp = 0; tmp < 5; tmp++) {
      X[tmp] = In3[tmp];
    }
  }

  /* Gain: '<Root>/Gain' */
  model_YDim = model_XDim;
  loop_ub = model_XDim - 1;
  for (tmp = 0; tmp <= loop_ub; tmp++) {
    Y[tmp] = 2.0 * X[tmp];
  }
</code></pre></p>

<p>In the generated code, notice how the variable <em>model_Xdim</em> has the lower and upper bound pre-allocated as 1 and 5, 5 being the width of the 3rd Inport block. Using these values, the <em>loop_ub</em> variable for the Switch block is calculated. </p>

<p>Thanks!</p>

<p>Aarti</p>

<p>Is this the code you expected?  Leave a <a href="http://blogs.mathworks.com/seth/?p=73&#comment">comment here</a> and tell me about it.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/Yf71tJ0eEkk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/11/06/generated-code-for-variable-size-signals/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/11/06/generated-code-for-variable-size-signals/</feedburner:origLink></item>
		<item>
		<title>STEM Educational Initiative Signing, and Robotics Competitions</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/pVbF5FxgHQ8/</link>
		<comments>http://blogs.mathworks.com/seth/2009/10/28/stem-educational-initiative-signing-and-robotics-competitions/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 03:00:43 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Community]]></category>

		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Robots]]></category>

		<category><![CDATA[Simulink]]></category>

		<category><![CDATA[STEM]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/10/28/stem-educational-initiative-signing-and-robotics-competitions/</guid>
		<description><![CDATA[It is not every day that I attend a speech by political
leaders of the Commonwealth of Massachusetts.


    Governor Patrick speeking about the value of science
technology engineering and math (STEM) education during his visit to The
MathWorks on October 14, 2009. Photo by Jeff Newcum

On October 14th, 2009 Massachusetts Governor
Deval Patrick signed an executive [...]]]></description>
			<content:encoded><![CDATA[<p>It is not every day that I attend a speech by political
leaders of the Commonwealth of Massachusetts.</p>

<p style="font-size:80%"><img src="http://blogs.mathworks.com/images/seth/2009Q4/stem_GovPatrickSpeech.jpg"
alt="Governor Deval Patrick speeking about the STEM Advisory Council at the MathWorks"><br />
    Governor Patrick speeking about the value of science
technology engineering and math (STEM) education during his visit to The
MathWorks on October 14, 2009. Photo by Jeff Newcum</p>

<p>On October 14<sup>th</sup>, 2009 Massachusetts Governor
Deval Patrick signed an executive order to establish the Science Technology
Engineering and Math (STEM) Advisory Council.  The MathWorks hosted the
gathering of local political leaders.  MathWorks CEO Jack Little introduced the
Lieutenant Governor Timothy Murray and the Governor Deval Patrick to a room
filled with MathWorkers.  I could describe all the formalities and go into what
this means for STEM education in Massachusetts, but other media sources covered
those topics (like <a href="http://www.edn.com/article/CA6701958.html?nid=2551">EDN</a>,
<a
href="http://www.masshightech.com/stories/2009/10/12/daily31-Governor-Patrick-creates-Mass-STEM-council.html">Mass
High Tech</a> and <a
href="http://www.mass.gov/?pageID=gov3pressrelease&amp;L=1&amp;L0=Home&amp;sid=Agov3&amp;b=pressrelease&amp;f=101409_STEM_advisory_council&amp;csid=Agov3">the
Governors official website</a>).  Instead I would like to focus on some of the
tangents to the main event.</p>

<p style="font-size:80%"><img src="http://blogs.mathworks.com/images/seth/2009Q4/stem_GovPatrickSigning.jpg"
alt="Governor Patrick signing the executive order to establish the STEM Advisory Council"><br />
Governor Patrick signing the executive order to establish the
STEM Advisory Council. Photo by Jeff Newcum</p>

<p><strong>Talking to the Governor</strong></p>

<p>My fellow blogger, <a href="http://blogs.mathworks.com/loren">Loren
Shure</a>, asked Governor Patrick what he thinks good corporate citizens can do
to support STEM education.</p>

<p style="font-size:80%"><img src="http://blogs.mathworks.com/images/seth/2009Q4/stem_DevalAndLoren.jpg"
alt="Loren Sure expressing her interests in STEM education to Governor Patrick"><br />
Loren Shure expressing her interests in STEM Education to
the Governor. Photo by Jeff Newcum</p>

<p>The Governor gave a couple examples of how companies can get
involved such as mentoring area students and engaging in student competitions. 
There already exist many opportunities to do this… </p>

<p><strong>Mentoring</strong></p>

<p>I have known many MathWorkers who volunteer at a <a
href="http://www.framingham.k12.ma.us/potter.cfm">local elementary school</a> as
math tutors in preparation for standardized tests.  The same school has a Lego®
Club where some of my colleagues mentor students on building robot using Lego®
Mindstorms.</p>

<p><strong>Competitions</strong></p>

<p>In Governor Patrick’s response to Loren, he gave a specific example
of a robotics competition, FIRST.</p>

<p>Most people have heard of <a href="http://www.usfirst.org/">FIRST</a>
(For Inspiration and Recognition of Science and Technology).  If you haven’t,
browse around the <a href="http://www.usfirst.org/">FIRST website</a> for a few
minutes and <em>get inspired</em> about the great things available to the next
generation of engineers and scientists.  They have programs targeted at many
different age groups, from the <a
href="http://www.usfirst.org/roboticsprograms/jfll/default.aspx?id=818">Junior FIRST
Lego League</a> for ages 6-9 years all the way up to “the varsity sport for the
mind” <a href="http://www.usfirst.org/roboticsprograms/frc/default.aspx?id=966">FIRST
Robotics Competition</a> for ages 14 to 18 years.</p>

<p>Targeted toward college students is the <a
href="http://www.ecocarchallenge.org/">EcoCAR Challenge</a> (which I wrote
about in a <a
href="http://blogs.mathworks.com/seth/2009/10/06/mathworks-hosts-eco-car/">recent
post</a>). MathWorks is a sponsor of the competition, and some of my colleagues
act at mentors to teams. The goal is to modify GM donate vehicles in an attempt
to reduce emissions, minimize fuel consumption AND maintain consumer appeal.  Those
college students involved are already on their way to careers in engineering.</p>

<p>Another competition I am very excited about is <a
href="http://www.etrobo.jp/ETROBO2009/">ET Robocon</a>, which MathWorks also
sponsors.  The site is in Japanese, but you can see <a
href="http://www.youtube.com/watch?v=w8wp29ay-x8">videos like this one</a> on
YouTube (<a
href="http://www.youtube.com/results?search_query=ET+Robocon&amp;search_type=&amp;aq=f">search
for ET Robocon</a>).  I see ET Robocon as an embedded software design
competition.  Teams all start with a standard LEGO® NXTway robot (a two-wheel
balancing robot built from LEGOs).  They have to develop an autonomous control
strategy and implement it to race robot around a pre-set track as fast as
possible.  Some of my colleagues from Japan developed the balancing algorithm using
Simulink and Real-Time Workshop Embedded Coder (available on the <a
href="http://www.mathworks.com/matlabcentral/fileexchange/19147-nxtway-gs-self-balancing-two-wheeled-robot-controller-design">File
Exchange here</a>).  All the teams have to incorporate that balancing software
into their larger design.  I learned that there are many university teams as
well as professional engineers from major companies involved in the
competition.</p>

<p><strong>Now It’s Your Turn</strong></p>

<p>Are you a mentor?  Are you involved in any of these or other
competitions that encourage students to explore STEM fields?  Leave a <a
href="http://blogs.mathworks.com/seth/?p=70&amp;#comment">comment here</a> and
share your experience.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/pVbF5FxgHQ8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/10/28/stem-educational-initiative-signing-and-robotics-competitions/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/10/28/stem-educational-initiative-signing-and-robotics-competitions/</feedburner:origLink></item>
		<item>
		<title>Radar Tracking in Simulink: Variable Size Signals</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/UNJBUdJ72hE/</link>
		<comments>http://blogs.mathworks.com/seth/2009/10/16/radar-tracking-in-simulink-variable-size-signals/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 19:00:42 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Guest Blogger]]></category>

		<category><![CDATA[Signal Processing]]></category>

		<category><![CDATA[Signals]]></category>

		<category><![CDATA[What's new?]]></category>

		<category><![CDATA[radar]]></category>

		<category><![CDATA[Simulink]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/10/16/radar-tracking-in-simulink-variable-size-signals/</guid>
		<description><![CDATA[This week I welcome guest blogger Aarti Ramani to talk about a long requested feature, variable size signals in Simulink.



Depending on target ranges, radar systems operate in
different modes (different lengths of data etc).  Let’s assume we have two
planes at two different altitudes. Now, what happens if there is a new plane in
sight? Since the number [...]]]></description>
			<content:encoded><![CDATA[This week I welcome guest blogger Aarti Ramani to talk about a long requested feature, variable size signals in Simulink.

<img src="http://blogs.mathworks.com/images/seth/2009Q4/Aarti_Ramani.jpg" alt="Aarti Ramani" />

<p>Depending on target ranges, radar systems operate in
different modes (different lengths of data etc).  Let’s assume we have two
planes at two different altitudes. Now, what happens if there is a new plane in
sight? Since the number of targets being detected by the radar is now changing,
how would you use Simulink to add this plane to its tracking list? </p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/radar_length_mode.png" alt="Radar mode and length"></p>

<p>A short and simple answer to this question is: <a
href="http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/ug/br4lzsy.html">Variable
Size Signals</a>. </p>

<p>I’ve read many customer requests wanting to be able to
change the dimensions of their Simulink variables while the simulation runs. Be
it a radar system which needs to operate in different modes based on its target
range to a simple combustion engine that needs to change its frame size based
on the number of samples per cycle, each of these system dynamics work with
signals whose sizes change during model execution.</p>

<p>Although, earlier I had to tell our customers that Simulink
did not have this capacity and you could not change a model’s signals
dimensions during execution; with R2009b, Simulink now supports variable-size
inputs and outputs in over 40 Simulink blocks.</p>

<p><strong>How does one create a variable size signal? </strong></p>

<p>There are several methods of creating a variable size
signal:  Switch blocks; Multi-Switch blocks with different input sizes; a Selector
block indexing options or custom code blocks (S-functions and Embedded MATLAB
blocks). </p>

<p>A common way of generating variable-size signals is to use a
Switch block for which each of the input signals differ in size. The Switch
Block now allows variable size signals to be passed in as inputs: </p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/switchBlockParams.png" alt="Block parameters for the Switch Block"></p>

<p>By simply selecting the option “Allow different data input
sizes”, you can obtain a variable size output signal whose dimensions change
with time.</p>

<p>As an
experiment, let us look at a simple demo model “sldemo_varsize_basic.mdl”. This demonstration
contains examples of how to use variable-size signals in a Simulink model, and
to show what kind of operations you can apply to them.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/varSizeBasic_diagram.png" alt="Variable size signals in a Simulink diagram."></span></p>

<p>Look at
how the Switch block, allowing 2 inputs of different dimensions, can be used
for operations like addition, vector concatenation etc.</p>

<p>You can also use the
“Selector” blocks to create a variable size signal. The Selector block generates as
output selected or reordered elements of an input vector, matrix, or
multidimensional signal. Using the “Starting and ending indices (port)”
indexing option, you can allow inputs of variable dimensions to generate
variable size signals.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/selectorBlockParams.png" alt="Selector block parameters"></span></p>

<p>You can use the Selector block to subreferece a matrix as shown below:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/varSizeBasic_selector.png" alt="Variable size signals from the selector block"></span></p>

<p><strong>How can I get the current dimensions or width of a
variable-size signal?</strong></p>

<p>You can use the Probe block to output the width of a signal.
</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/probeBlockParams.png" alt="Probe block parameters"></p>

<p>The Probe
allows you to visualize and save the signal dimensions and view the I/O and
state data for blocks selected.  This could also be used in a calculation that
requires sample size information.</p>

<p><strong>How can I convert a variable-size signal into a
fixed-size signal?</strong></p>

<p>To convert a variable size signal into a fixed size signal,
you can use the “Assignment” block.  The variable-size signal feeds into the second
input port of the Assignment block and can be used to convert the incoming
signal into a fixed size signal. </p>

<p>By allowing signal sizes in Simulink models to vary during
execution, one can easily model systems with varying environments, resources,
and constraints. So, coming back to our radar system, using variable size
signals, you can now create a conceptual air traffic control (ATC) radar
simulation based on your radar range equation(s):</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/aero_atc.png" alt="Simulink radar model"></p>

<p>For more details on how this snazzy feature works, check out
the <a
href="http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/ug/br4lzsy.html">Variable
Sizing documentation</a>.</p>

<p><strong>Now it’s your turn</strong></p>

<p>Do you plan to upgrade to R2009b and use variable size signals? 
Leave a <a href="http://blogs.mathworks.com/seth/?p=69&#comment">comment here</a> and tell me what you plan to model.</p>
<img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/UNJBUdJ72hE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/10/16/radar-tracking-in-simulink-variable-size-signals/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/10/16/radar-tracking-in-simulink-variable-size-signals/</feedburner:origLink></item>
		<item>
		<title>MathWorks Hosts EcoCAR</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/sMBDICbHIuA/</link>
		<comments>http://blogs.mathworks.com/seth/2009/10/06/mathworks-hosts-eco-car/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 03:00:21 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Community]]></category>

		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Model-Based Design]]></category>

		<category><![CDATA[EcoCAR Challenge]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/10/06/mathworks-hosts-eco-car/</guid>
		<description><![CDATA[Recently, when I arrived at work, I found this parked on the
lawn:



This is the EcoCAR from the EcoCAR Challenge. MathWorks hosted
about one hundred students from the EcoCAR teams for the EcoCAR Year 2 Fall
Workshop.

A Big Shiny Embedded Target

When I first saw the EcoCAR sitting on the lawn, I wondered
what system target file they might use:



I’m [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, when I arrived at work, I found this parked on the
lawn:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/EcoCar_onLawnSmall.jpg" alt="EcoCAR Chalenge Year 2 Fall Workshop at The MathWorks"></p>

<p>This is the EcoCAR from the <a
href="http://www.ecocarchallenge.org/">EcoCAR Challenge</a>. MathWorks hosted
about one hundred students from the EcoCAR teams for the EcoCAR Year 2 Fall
Workshop.</p>

<p><strong>A Big Shiny Embedded Target</strong></p>

<p>When I first saw the EcoCAR sitting on the lawn, I wondered
what system target file they might use:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q4/EcoCarTLC_small.png" alt="An imaginary EcoCAR System TLC file."></p>

<p>I’m sure there are a lot of cool things these students will
be able to do with a great piece of hardware like this, but in many ways, it’s
just a big, shinny embedded target.</p>

<p><strong>What is EcoCAR?</strong></p>

<p>EcoCAR is an academic competition.  A quote from <a
href="http://www.ecocarchallenge.org/about_ecocar.html">ecocarchallenge.org</a>
sums it up:</p>

<p><quote>“The competition challenges 17 universities across North
        America to reduce the environmental impact of vehicles by minimizing the
        vehicle’s fuel consumption and reducing its emissions while retaining the
        vehicle’s performance, safety and consumer appeal. Students use a real-world
        engineering process to design and integrate their advanced technology solutions
into a 2009 Saturn Vue.”</quote></p>

<p>The students had 5 days of training in different tracks to
learn and apply MathWorks tools to the design problems facing them.  If you
read the <a href="http://greengarageblog.org/">Green Car Garage blog</a>, you
may have read about <a
href="http://greengarageblog.org/2009/09/23/the-mathworks-welcomes-future-automotive-engineers/">the
event</a> and <a
href="http://greengarageblog.org/2009/09/24/racing-toward-sustainability-engineers-in-the-loop-eil/">the
fun</a> teams had during their visit to Boston. Nicole Lambiase from <a
href="http://www.anl.gov/">Argon National Lab</a> wrote a <a
href="http://greengarageblog.org/2009/10/02/switching-gears-reflections-on-the-fall-workshop-from-student-turned-organize">post
commenting</a> that it really takes a village to make these competition events
run smoothly.  Some of the people in that village are members of the
Model-Based Design community.  A lot of my colleagues volunteer with EcoCAR
Challenge.  Many of them traveled from our Michigan office to lead trainings
and mentor students that attended.  </p>

<p><strong>The Trouble with Model-Based Design</strong></p>

<p>The trouble with Model-Based Design is that there are very
few people and institutions available to help you learn it.  I never had a
class on Model-Based Design when I went to school.  The EcoCAR Challenge is an opportunity
to develop the next generation of engineers skilled in Model-Based Design.  MathWorks
is very committed to mentoring these future engineers.  This aligns with our academic
mission to accelerate the pace of learning, discovery, and research in
engineering and science.</p>

<p><strong>How about you?</strong></p>

<p>How did you learn about modeling and Model-Based Design?  Who
was your mentor? Leave a <a
href="http://blogs.mathworks.com/seth/?p=68&amp;#comment">comment here</a> and
share your story.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/sMBDICbHIuA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/10/06/mathworks-hosts-eco-car/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/10/06/mathworks-hosts-eco-car/</feedburner:origLink></item>
		<item>
		<title>Custom Components in Physical Models</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/KGJPeCF0cQE/</link>
		<comments>http://blogs.mathworks.com/seth/2009/09/25/custom-components-in-physical-models/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 16:00:08 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Guest Blogger]]></category>

		<category><![CDATA[Physical Modeling]]></category>

		<category><![CDATA[What's new?]]></category>

		<category><![CDATA[Simscape]]></category>

		<category><![CDATA[simscape language]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/09/25/custom-components-in-physical-models/</guid>
		<description><![CDATA[This week I want to introduce
guest blogger Steve
Miller to talk about the Simscape language.







Introduction to the Simscape
Language



I’ve been working with MATLAB and
Simulink since my college days, and one of the things I liked most about these
tools is that I’m free to create just about anything with the commands and
blocks.  Whenever my boss asked me, “Do [...]]]></description>
			<content:encoded><![CDATA[<p>This week I want to introduce
guest blogger <a
href="http://www.mathworks.com/matlabcentral/fileexchange/authors/29641">Steve
Miller</a> to talk about the Simscape language.</p>



<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/SteveMiller.jpg" alt="Steve Miller - Physical Modeling Expert"></p>



<p><strong>Introduction to the Simscape
Language</strong></p>



<p>I’ve been working with MATLAB and
Simulink since my college days, and one of the things I liked most about these
tools is that I’m free to create just about anything with the commands and
blocks.  Whenever my boss asked me, “Do you think you could use MATLAB to...,”
the enthusiastic “Yes!” was halfway out of my mouth before he even reached the
end of the sentence.</p>



<p>When I started working with the <a href="http://physical-modeling.mathworks.com/">physical
modeling</a> products at The MathWorks,
I was hoping that I’d have the same freedom there.  Well, starting with Release
2008b, I do!  Using the <a
href="http://www.mathworks.com/products/simscape/description4.html">Simscape language</a> (an
enhancement to Simscape, which was first released in R2007a), I can create my
own physical modeling blocks just like I created cool MATLAB scripts and
Simulink subsystems to solve all those tricky problems my boss threw at me.</p>



<p><strong>What is the Simscape language?</strong></p>



<p>The Simscape language is a
MATLAB-based, object-oriented language for modeling physical systems.  The big
difference here is that I can use this textual language to create components
that have physical connections, such as hydraulic ports on valves and electrical
terminals on resistors, instead of inputs and outputs like I’m used to doing in
Simulink.  Why is this important?  Well the models built with physical
connections are much easier to understand – models of electrical systems look
like an electrical schematic.  And, if I create something useful and I want to
reuse it in another model, it is much easier, for I don’t have to worry about
routing inputs and outputs -- I just plug my new electrical component into the
circuit and try it.</p>



<p>Here is an example of a component
I have defined using the Simscape language.  It’s a DC motor.  You’ll see that
it has four physical ports (not inputs and outputs) – two electrical and two
mechanical.  These physical ports let me plug the component into a physical
network.</p>



<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/Simscape_Language_Post_Image_1a.png" alt="Simscape - Custom DC Motor library"></p>



<p><strong>How does it work?</strong></p>



<p>You can use the Simscape language
to define physical domains, components, and libraries of components.  It’s
usually easiest to look at an example, so let’s look at the definition of a DC
motor  created in the Simscape language.</p>



<p>Here we see the first 11 lines of
the file.  This is where we define the component name, add a description, and
define the physical ports:</p>



<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/Simscape_Language_Post_Image_2a.png" alt="Simscape Component Definition of Nodes"></p>



<p>You can see that we have two
electrical (+ and – terminals) and two mechanical rotational ports (motor shaft
and motor housing).  These are reflected in the component shown above.  </p>



<p>In the next 6 lines of the file,
we define the parameters (including units!).  These are the values that I or
another user may want to change:</p>



<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/Simscape_Language_Post_Image_3a.png" alt="Simscape parameters section"></p>



<p>You’ll notice that in the final
component, the prompt, the default value, and the units all show up in the
dialog box shown here:  </p>



<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/Simscape_Language_Post_Image_4a.png" alt="Simscape Custom DC Motor Parameters dialog box"></p>

<p>Just like most Simscape blocks,
there a link to the source code!  In lines 18-23 of the file, we define the
variables associated with the physical domains (electrical and mechanical) we need for the equations we will define in the
equations section.</p>



<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/Simscape_Language_Post_Image_5a.png" alt="Simscape variables section"></p>



<p>In the setup section, we set up
the connections between the variables to the physical ports.  Remember
Kirchoff’s laws?  Well, we’re essentially applying them to both the electrical
and mechanical domains (yep, they work in other physical domains, too, if you
define them properly).  </p>



<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/Simscape_Language_Post_Image_6a.png" alt="Simscape function setup section"></p>



<p>You’ll also notice that we have used
MATLAB to make sure that the value of the resistance in the dialog box is not
less than zero.  I can use MATLAB code in this section to do other things like
calculate values or initialize variables.  All that MATLAB I learned is not
going to waste!</p>



<p>In the last lines of the file, I
define the equations for the motor.  Take a look:</p>



<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/Simscape_Language_Post_Image_7a.png" alt="Simscape equations section"></p>



<p style='text-autospace:none'>See
the “==” symbol there?  I’ve used that to define an implicit equation.  This
means I have set up a relationship between these quantities (including time
derivatives – see the <strong>.</strong><strong><span style='font-family:"Courier New";color:blue'>der</span></strong>?).
 I’m not assigning values, nor does this represent a Boolean
expression.  I could have defined them as shown below and the results would be
the same:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/Simscape_Language_Post_Image_8a.png" alt="Simscape equations section - alternative"></p>



<p>And there you have it!  Once I
have defined the file, I execute <a
href="http://www.mathworks.com/access/helpdesk/help/toolbox/physmod/simscape/ref/ssc_build.html">ssc_build</a>
and it produces a Simscape component I can connect to other Simscape components
in my physical model.</p>



<p><strong>Videos of Simscape language in
action</strong></p>



<p>I have made a video demo of <a
        href="http://www.mathworks.com/products/demos/simscape/Simscape_Language_Nonlinear_Spring/">
    modeling a nonlinear spring using the Simscape language</a>.  Take a look to see the blocks in use and the build
process.</p>



<p>For a more complete experience,
watch this <a href="http://www.mathworks.com/wbnr31004">
webinar on the Simscape language</a>.</p>



<p><strong>Now it’s your turn</strong></p>



<p>Want a closer look at this
example?  <a
href="http://www.mathworks.com/matlabcentral/fileexchange/25014">
Download it</a> from the
MATLAB Central File Exchange.</p>



<p>Are you using the physical
modeling tools? Have you tried the Simscape language? Post a 
<a href="http://blogs.mathworks.com/seth/?p=67&amp;#comment">
comment here</a> and tell us
about it.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/KGJPeCF0cQE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/09/25/custom-components-in-physical-models/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/09/25/custom-components-in-physical-models/</feedburner:origLink></item>
		<item>
		<title>How do I test for NaN in Simulink R2009b? (NEW!)</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/EnmGi2a6SZM/</link>
		<comments>http://blogs.mathworks.com/seth/2009/09/18/how-do-i-test-for-nan-in-simulink-r2009b-new/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 16:00:15 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Numerics]]></category>

		<category><![CDATA[What's new?]]></category>

		<category><![CDATA[isNaN]]></category>

		<category><![CDATA[R2009b]]></category>

		<category><![CDATA[Simulink]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/09/18/how-do-i-test-for-nan-in-simulink-r2009b-new/</guid>
		<description><![CDATA[



Back in February 2009 I posted about how
to test for NaN in Simulink.  The approach I talked about was more of a
logical experiment based on the special properties of NaN than an ideal
software solution.  In Simulink R2009b the Relational
Operator block got an upgrade to include isNaN.  Let’s see how it works.

Relational Operator Block Upgrade

The Relational [...]]]></description>
			<content:encoded><![CDATA[<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:0in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
pre
	{mso-style-link:"HTML Preformatted Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";
	color:#1122AA;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
	{mso-style-link:"Balloon Text Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:8.0pt;
	font-family:"Tahoma","sans-serif";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
span.BalloonTextChar
	{mso-style-name:"Balloon Text Char";
	mso-style-link:"Balloon Text";
	font-family:"Tahoma","sans-serif";}
span.HTMLPreformattedChar
	{mso-style-name:"HTML Preformatted Char";
	mso-style-link:"HTML Preformatted";
	font-family:"Courier New";
	color:#1122AA;}
span.ln1
	{mso-style-name:ln1;
	color:#888888;
	font-style:italic;}
span.ct1
	{mso-style-name:ct1;
	color:#117755;
	font-style:italic;}
span.dt1
	{mso-style-name:dt1;
	color:#112266;}
span.pp1
	{mso-style-name:pp1;
	color:#992211;}
span.kw1
	{mso-style-name:kw1;
	color:#112266;}
.MsoPapDefault
	{margin-bottom:10.0pt;
	line-height:115%;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
-->
</style>

<p>Back in February 2009 I posted about <a
href="http://blogs.mathworks.com/seth/2009/02/04/how-do-i-test-for-nan-in-my-model/">how
to test for NaN in Simulink</a>.  The approach I talked about was more of a
logical experiment based on the special properties of NaN than an ideal
software solution.  In Simulink R2009b the <a
href="http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/slref/relationaloperator.html">Relational
Operator block</a> got an upgrade to include isNaN.  Let’s see how it works.</p>

<p><strong>Relational Operator Block Upgrade</strong></p>

<p>The Relational Operator is often used to compare signals and
test for greater than (&gt;), equals (==), and more.  In R2009b it has the
following new single input modes: isNaN, isFinite, and isInf<strong>.</strong></p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/isNaNBlock.png" alt="The Relational Operator in Simulink R2009b has the isNaN operation."></p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/relOpParameters.png" alt="The parameters for the relational operator block in Simulink R2009b"></p>

<p>These functions are familiar to those who program in MATLAB
and they work the same way.  When the input signal has the properties we are
testing for, the block outputs true.</p>

<p><strong>How does it work?</strong></p>

<p>I talked to my colleague Omar who upgraded the block and he
shared with me some key points.  He mentioned that the block handles:</p>

<p><ul>
        <li>real and complex signals</li>
        <li>any data type supported by Simulink including fixed point types</li>
        <li>endianness of your platform</li>
    </ul>
</p>

<p>These new operators are only meaningful with data types that
can represent Inf and NaN.   <em>So how does it work with non-floating point
types?</em>  If you pass in an integer, or a fixed-point type that cannot
represent NaN of Inf, the block returns false.  This is a key point for
workflows where you might find yourself switching the data types in your design. 
This often happens when selecting proper fixed-point data type properties.  If
you are running simulations to gather ideal double precision results, you may
need to handle Inf and NaN.  When converting the model to fixed-point for implementation,
the algorithm does not require any modifications.</p>

<p><strong>Generated Code</strong></p>

<p>The code generated for the isNaN function looks like this:</p>

<p style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><em><span style='font-size:10.0pt;font-family:"Courier New";color:#888888'>  
34   </span></em><span style='font-size:10.0pt;font-family:"Courier New";
color:#1122AA'>  </span><em><span style='font-size:10.0pt;font-family:"Courier New";
color:#117755'>/* Outport: ‘</span></em><em><span style='font-size:10.0pt;
font-family:"Courier New";color:#117755'>&lt;Root&gt;/Out1</span></em><em><span
style='font-size:10.0pt;font-family:"Courier New";color:#117755'>’
incorporates:</span></em><br />

<em><span style='font-size:10.0pt;font-family:"Courier New";color:#888888'>  
35   </span></em><em><span style='font-size:10.0pt;font-family:"Courier New";
color:#117755'>   *  Inport: ‘</span></em><em><span style='font-size:10.0pt;
font-family:"Courier New";color:#117755'>&lt;Root&gt;/In1</span></em><em><span
style='font-size:10.0pt;font-family:"Courier New";color:#117755'>’</span></em><br />

<em><span style='font-size:10.0pt;font-family:"Courier New";color:#888888'>  
36   </span></em><em><span style='font-size:10.0pt;font-family:"Courier New";
color:#117755'>   *  RelationalOperator: ‘</span></em><em><span style='font-size:10.0pt;
font-family:"Courier New";color:#117755'>&lt;Root&gt;/Relational Operator</span></em><em><span
style='font-size:10.0pt;font-family:"Courier New";color:#117755'>’</span></em><br />

<em><span style='font-size:10.0pt;font-family:"Courier New";color:#888888'>  
37   </span></em><em><span style='font-size:10.0pt;font-family:"Courier New";
color:#117755'>   */</span></em><br />

<em><span style='font-size:10.0pt;font-family:"Courier New";color:#888888'>  
38   </span></em><span style='font-size:10.0pt;font-family:"Courier New";
color:#1122AA'>  isNaNCode_Y.Out1 = </span><span style='font-size:10.0pt;font-family:
"Courier New"'>rtIsNaN</span><span style='font-size:10.0pt;font-family:
"Courier New";color:#1122AA'>(isNaNCode_U.In1);</span><br />



<p>The function rtIsNaN is part of rt_nonfinite.c:</p>

<pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span class=ln1>   61   </span><span class=ct1>/* Test if value is not a number */</span></pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span
class=ln1>   62   </span><span style='color:#1122AA'>boolean_T</span> rtIsNaN(<span style='color:#1122AA'>real_T</span> value)</pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span
class=ln1>   63   </span><strong>{</strong></pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span class=ln1>   64   </span></pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span
class=ln1>   65   </span><span style='color:#992211'>#<span class=pp1>if</span></span> <span
class=pp1>defined</span>(_MSC_VER) &amp;&amp; (_MSC_VER &lt;= 1200)</pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span
class=ln1>   66   </span></pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span class=ln1>   67   </span>  <span
class=ct1>/* For MSVC 6.0, use a compiler specific comparison function */</span></pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span
class=ln1>   68   </span>  <span class=kw1>return</span> _isnan(value)? 1U:0U;</pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span
class=ln1>   69   </span></pre><pre><span class=ln1>   70   </span><span
style='color:#992211'>#<span class=pp1>else</span></span></pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span
class=ln1>   71   </span></pre><pre><span class=ln1>   72   </span>  <span
class=kw1>return</span>((value!=value) ? 1U : 0U);</pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span class=ln1>   73   </span></pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span
class=ln1>   74   </span><span style='color:#992211'>#<span class=pp1>endif</span></span></pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span
class=ln1>   75   </span></pre><pre style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span class=ln1>   76   </span><strong>}</strong></pre>



<p><strong>Further Optimization using Target Function Library</strong></p>

<p>If your embedded target environment has a special function
for handling tests for NaN, Inf or Finiteness you can use the <a
href="http://www.mathworks.com/access/helpdesk/help/toolbox/ecoder/ug/brc_o1j.html">Target
Function Library</a> to replace the call to rtIsNaN with that call.</p>

<p><strong>What do you think?</strong></p>

<p>Will you use the isInf, isNaN and isFinite mode of this
block?  Leave a <a href="http://blogs.mathworks.com/seth/?p=66&amp;#comment">comment
here</a> to tell me how.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/EnmGi2a6SZM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/09/18/how-do-i-test-for-nan-in-simulink-r2009b-new/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/09/18/how-do-i-test-for-nan-in-simulink-r2009b-new/</feedburner:origLink></item>
		<item>
		<title>New Stuff – Simulink R2009b</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/8hTuxzZ91hI/</link>
		<comments>http://blogs.mathworks.com/seth/2009/09/09/new-stuff-%e2%80%93-simulink-r2009b/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 01:56:01 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Libraries]]></category>

		<category><![CDATA[Masking]]></category>

		<category><![CDATA[Model Reference]]></category>

		<category><![CDATA[Simulation]]></category>

		<category><![CDATA[What's new?]]></category>

		<category><![CDATA[R2009b]]></category>

		<category><![CDATA[Simulink]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/09/09/new-stuff-%e2%80%93-simulink-r2009b/</guid>
		<description><![CDATA[Last week the MathWorks released the R2009b family of
products.  There are many new capabilities in the latest release and with this
blog post, I want to highlight a some of the features in Simulink I’m really
excited about.  While you read this, start installing the latest products from
the MathWorks.com
downloads area (login and license required).

Reading the release notes [...]]]></description>
			<content:encoded><![CDATA[<p>Last week the MathWorks released the R2009b family of
products.  There are many new capabilities in the latest release and with this
blog post, I want to highlight a some of the features in Simulink I’m really
excited about.  While you read this, start installing the latest products from
the <a href="http://www.mathworks.com/downloads/web_downloads">MathWorks.com
downloads area</a> (login and license required).</p>

<p><strong>Reading the release notes is so R2007b!</strong></p>

<p>Did you know that there is a presentation containing <a
href="http://www.mathworks.com/products/new_products/Simulink_R2009b.pdf">highlights
and screen shots from R2009b Simulink</a>?  If you have missed this in the
past, you can go back and check out <a
href="http://www.mathworks.com/products/new_products/Simulink_R2008a_v3.pdf">R2008a</a>,
<a href="http://www.mathworks.com/products/new_products/Simulink_R2008b.pdf">R2008b</a>
and <a href="http://www.mathworks.com/products/new_products/Simulink_R2009a.pdf">R2009a</a>
highlights.  Try it yourself, and browse through all the <a
href="http://www.mathworks.com/products/new_products/Simulink_R2009b.pdf">cool
new features in R2009b Simulink</a>.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/FeatureSlides9b.png" alt="R2009b Simulink Feature Slides"></p>

<p><strong>Model Reference Protected Models!</strong></p>

<p>Share your model functionality without sharing your model
intellectual property!  Anyone with R2009b Simulink can use a protected model. 
If you have a license to Real-Time Workshop, you can create a protected model.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/mdlrefProtected.png" alt="Model Reference Protected Mode"></p>

<p><strong>Model Reference Variants</strong></p>

<p>If you have multiple implementations of your component model,
variant objects enable you to control the implementation used.  This allows you
to globally control and coordinate switching between variant implementations of
your model.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/mdlrefVariants.png" alt="Simulink Model Reference Variants"></p>

<p><strong>Tabs in the Mask Editor!</strong></p>

<p>Now you can create tabs in your custom block masks.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/maskTabs.png" alt="Simulink R2009b masks include tabs!"></p>

<p><strong>Variably Sized Signals!</strong></p>

<p>Special blocks and Embedded MATLAB now support dynamically
sizing signals during simulation!</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/varSize.png" alt="Variable sized signals in Simulink R2009b"></p>

<p><strong>The SIM command can return a single output!</strong></p>

<p>The SIM command has a new single output syntax so all your results
are part of a single SimulationOutput object. This enables SIM to be called
within a PARFOR loop, thus enabling easy parallel Simulation using the Parallel
Computing Toolbox.</p>

<code style="font-size: 11pt;">paramNameValStruct.SimulationMode = 'rapid';<br />
    paramNameValStruct.AbsTol = '1e-5';<br />
    paramNameValStruct.SaveState = 'on';<br />
    paramNameValStruct.StateSaveName = 'xoutNew';<br />
    paramNameValStruct.SaveOutput = 'on';<br />
    paramNameValStruct.OutputSaveName = 'youtNew';<br />
    simOut = sim('vdp',paramNameValStruct);</code>

<p><strong>New Library Links Tool for fixing broken links!</strong></p>

<p>After making changes to a model and disabling library links,
the Library Links tool will enable you to reestablish those links to your
library.  Each change in the model can be pushed back into the library, or the
block can be restored from the original library source. </p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/linksTool.png" alt="The R2009b Simulink Library Links Tool"></p>

<p><strong>Now it’s your turn</strong></p>

<p>Have you downloaded R2009b?  Leave a <a
href="http://blogs.mathworks.com/seth/?p=65&amp;#comment">comment here</a> and
tell me about your favorite new features.</p>
<img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/8hTuxzZ91hI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/09/09/new-stuff-%e2%80%93-simulink-r2009b/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/09/09/new-stuff-%e2%80%93-simulink-r2009b/</feedburner:origLink></item>
		<item>
		<title>BEEP, Simulink versus MATLAB</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/72Lcyo0RZXE/</link>
		<comments>http://blogs.mathworks.com/seth/2009/08/28/beep-simulink-versus-matlab/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 21:44:05 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Fun]]></category>

		<category><![CDATA[beep]]></category>

		<category><![CDATA[MATLAB]]></category>

		<category><![CDATA[Simulink]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/28/beep-simulink-versus-matlab/</guid>
		<description><![CDATA[Did you ever notice that a BEEP in Simulink means something
different from a BEEP in MATLAB?

BEEP, What BEEP?

 What I’m talking about is that bell character you sometimes
hear.  In older version of MATLAB (Pre R14), you could actually display a beep
on the screen. 

&#62;&#62; fprintf('\a')

&#62;&#62; disp(char(7))



In more recent version, the command window doesn’t display
the BEEP character.  [...]]]></description>
			<content:encoded><![CDATA[<p>Did you ever notice that a BEEP in Simulink means something
different from a BEEP in MATLAB?</p>

<p><strong>BEEP, What BEEP?</strong></p>

<p> What I’m talking about is that bell character you sometimes
hear.  In older version of MATLAB (Pre R14), you could actually display a beep
on the screen. </p>

<code style="font-size: 11pt;"><span style='font-size:12.0pt;font-family:"Courier New";
color:black'>&gt;&gt; fprintf('\a')</span><br />

<span style='font-size:12.0pt;font-family:"Courier New";
color:black'>&gt;&gt; disp(char(7))</span></code>



<p>In more recent version, the command window doesn’t display
the BEEP character.  Instead, you can call the function <a
href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/beep.html">BEEP</a>.</p>

<code style="font-size: 11pt;"><span style='font-size:12.0pt;font-family:"Courier New";
color:black'>&gt;&gt; beep</span></code>



<p>You hear it under different circumstances for Simulink
versus MATLAB.</p>

<p><strong>MATLAB BEEP == Error</strong></p>

<p>In MATLAB, the BEEP alerts you to an error.  Sometimes you
get it because your calling syntax is wrong, sometimes when the tab completion can’t
find anything.  In MATLAB, BEEP is bad.</p>

<code style="font-size: 11pt;"><span style='font-size:12.0pt;font-family:"Courier New";
color:black'>&gt;&gt; plot(x,y</span><br />

<span style='font-size:12.0pt;font-family:"Courier New";
color:red'>??? plot(x,y</span><br />

<span style='font-size:12.0pt;font-family:"Courier New";
color:red'>            |</span><br />

<span style='font-size:12.0pt;font-family:"Courier New";
color:red'>Error: Expression or statement is incorrect--possibly<br /> unbalanced
(, {, or [.</span></code>

<p><strong>Simulink BEEP == Done</strong></p>

<p>In Simulink, the BEEP happens when your simulation is
finished.  It is a beautiful sound.  The BEEP is an alert to tell you the work
is done.  The fruit of your simulation is ready to harvest. It is time to
review your results. In Simulink, BEEP is a good sound.</p>

<code style="font-size: 11pt;"><span style='font-size:12.0pt;font-family:"Courier New";
color:black'>&gt;&gt; vdp</span><br />
<span style='font-size:12.0pt;font-family:"Courier New";
color:black'>&gt;&gt; set_param(bdroot,</span><span style='font-size:12.0pt;
font-family:"Courier New";color:#A020F0'>'SimulationCommand'</span><span
style='font-size:12.0pt;font-family:"Courier New";color:black'>,</span><span
style='font-size:12.0pt;font-family:"Courier New";color:#A020F0'>'start'</span><span
style='font-size:12.0pt;font-family:"Courier New";color:black'>)</span></code>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/vdpBEEP.png" alt="The VDP model in Simulink"></p>

<p>Leave your comments, <a
href="http://blogs.mathworks.com/seth/?p=64&amp;#comment">after the BEEP</a>. (THANK YOU Jeannette for alerting me to the difference.)</p>
<img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/72Lcyo0RZXE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/08/28/beep-simulink-versus-matlab/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/08/28/beep-simulink-versus-matlab/</feedburner:origLink></item>
		<item>
		<title>A Better If-Else Construct</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/hGzYnCJm9PI/</link>
		<comments>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 01:55:12 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
		
		<category><![CDATA[Code Generation]]></category>

		<category><![CDATA[Modeling]]></category>

		<category><![CDATA[Real-Time Workshop]]></category>

		<category><![CDATA[Simulink Tips]]></category>

		<category><![CDATA[If Else]]></category>

		<category><![CDATA[Merge Block]]></category>

		<category><![CDATA[Simulink]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/</guid>
		<description><![CDATA[



In a previous post, I answered a question about how
to model an If-Else behavior.  Here I will restate the algorithm I want to create:

if(sel==0)
out = 2*in1;
elseif (sel==1)
out = 3*in2;

The first answer I gave relied upon a Switch block and the Conditional
Input Branch Execution optimization to get an efficient If-Else construct
in the model.  While this works, [...]]]></description>
			<content:encoded><![CDATA[<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:0in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
pre
	{mso-style-link:"HTML Preformatted Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";
	color:#1122AA;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
	{mso-style-link:"Balloon Text Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:8.0pt;
	font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
	{mso-style-name:"Balloon Text Char";
	mso-style-link:"Balloon Text";
	font-family:"Tahoma","sans-serif";}
span.HTMLPreformattedChar
	{mso-style-name:"HTML Preformatted Char";
	mso-style-link:"HTML Preformatted";
	font-family:"Courier New";
	color:#1122AA;}
span.ln1
	{mso-style-name:ln1;
	color:#888888;
	font-style:italic;}
span.ct1
	{mso-style-name:ct1;
	color:#117755;
	font-style:italic;}
span.kw1
	{mso-style-name:kw1;
	color:#112266;}
.MsoPapDefault
	{margin-bottom:10.0pt;
	line-height:115%;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
	{page:Section1;}
-->
</style>

<p>In a previous post, I answered a question about <a
href="http://blogs.mathworks.com/seth/2009/06/02/the-if-else-construct-in-models/">how
to model an If-Else behavior</a>.  Here I will restate the algorithm I want to create:</p>

<p><em>if(sel==0)<br />
out = 2*in1;<br />
elseif (sel==1)<br />
out = 3*in2;</em></p>

<p>The first answer I gave relied upon a Switch block and the <em>Conditional
Input Branch Execution</em> optimization to get an efficient If-Else construct
in the model.  While this works, I don’t like reliance on an optimization to
provide good behavior.  Sometimes, small changes to the model prevent Simulink
from applying an optimization.  I think it is best to implement requirements explicitly. 
In this post, I want to show you a way to model explicitly an If-Else conditional
execution behavior.</p>

<p><strong>Conditionally Executed Subsystems and Merge</strong></p>

<p>The If-Else construct requires decision logic to control the
execution of algorithm contained within the expression.  One way to do this is
using the If block (from the Ports &amp; Subsystems library), combined with the
If Action Subsystem.  The If Action Subsystem executes based on the conditional
expression in the If block.  If you have used Function Call subsystems, this is
very similar.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/ifActionConstruct.png" alt="The If Else, Else If, Action construct in Simulink blocks."></p>

<p>The If block provides control over If and ElseIf conditions,
and there is even an option to provide an Else signal.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/ifBlockParameters.png" alt="The Simulink If Block parameters."></p>

<p>This model will give you the conditional execution of the
two subsystem, however, the subsystems write their outputs to separate signals.
 How do you get two subsystem to write to the same signal?</p>

<p><strong>Merge the Signals</strong></p>

<p>The Merge block provides a way for both subsystems to write
to the same signal.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2009Q3/MergeSignals.png" 
alt="The Merge Block provides a way to specify that multiple signal write to the same memory location."></p>

<p>In many ways, the Merge block doesn’t behave like a block
with the traditional input/output relationship.  I think of it more like a
jumper across multiple wires.  The merge block specifies that all signals
connected to it have the same value and actually share the same memory.  This
is the programming practice of specifying multiple writers to the same
variable.</p>

<p><strong>Generated Code with Merge</strong></p>

<p>The code generated from the above model looks a lot like our
original algorithm.</p>

<code style="font-size: 12pt;"><span class=ln1>   34   </span>  <span class=ct1>/* If: '&lt;Root&gt;/If' incorporates:</span><br /><span
class=ln1>   35   </span><span class=ct1>   *  ActionPort: '&lt;S1&gt;/Action Port'</span><br /><span
class=ln1>   36   </span><span class=ct1>   *  ActionPort: '&lt;S2&gt;/Action Port'</span><br /><span
class=ln1>   37   </span><span class=ct1>   *  Inport: '&lt;Root&gt;/In3'</span><br /><span
class=ln1>   38   </span><span class=ct1>   *  SubSystem: '&lt;Root&gt;/If Action Subsystem'</span><br /><span
class=ln1>   39   </span><span class=ct1>   *  SubSystem: '&lt;Root&gt;/If Action Subsystem1'</span><br /><span
class=ln1>   40   </span><span class=ct1>   */</span><br /><span
class=ln1>   41   </span>  <span class=kw1>if</span> (sel == 0.0) <strong>{</strong><br /><span
class=ln1>   42   </span>    <span class=ct1>/* Gain: '&lt;S1&gt;/Gain' incorporates:</span><br /><span
class=ln1>   43   </span><span class=ct1>     *  Inport: '&lt;Root&gt;/In1'</span><br /><span
class=ln1>   44   </span><span class=ct1>     */</span><br /><span
class=ln1>   45   </span>    out = 2.0 * u1;<br /><span class=ln1>   46   </span>  <strong>}</strong> <span
class=kw1>else</span> <strong>{</strong><br /><span class=ln1>   47   </span>    <span
class=kw1>if</span> (sel == 1.0) <strong>{</strong><br /><span class=ln1>   48   </span>      <span
class=ct1>/* Gain: '&lt;S2&gt;/Gain' incorporates:</span><br /><span
class=ln1>   49   </span><span class=ct1>       *  Inport: '&lt;Root&gt;/In2'</span><br /><span
class=ln1>   50   </span><span class=ct1>       */</span><br /><span
class=ln1>   51   </span>      out = 3.0 * u2;<br /><span class=ln1>   52   </span>    <strong>}</strong><br /><span
class=ln1>   53   </span>  <strong>}</strong></code>



<p><strong>Correct use of Merge</strong></p>

<p>Because Merge blocks are a memory specification rather than
an algorithmic construct, there are some <a
href="http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/slref/merge.html">guidelines
for using merge blocks</a>.  The documentation shows some correct and incorrect
usage patterns.  If you use merge block in your model, I suggest you run the <a
href="http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/slref/bq6d4aa-1.html#bragjl8-1">Model
Advisor Check for proper Merge block usage</a>.</p>

<p><strong>Now it’s your turn</strong></p>

<p>Do you use the Merge block in your models?  Leave a <a
href="http://blogs.mathworks.com/seth/?p=63&amp;#comment">comment here</a> and
share your experience.</p>
<img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/hGzYnCJm9PI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/feed/</wfw:commentRss>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2009/08/20/a-better-if-else-construct/</feedburner:origLink></item>
	</channel>
</rss>
