<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	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:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Simulink &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/simulink/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 11 Feb 2015 18:00:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>Simulink Data Dictionary</title>
		<link>https://undocumentedmatlab.com/articles/simulink-data-dictionary?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simulink-data-dictionary</link>
					<comments>https://undocumentedmatlab.com/articles/simulink-data-dictionary#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 11 Feb 2015 18:00:11 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Donn Shull]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Simulink]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5571</guid>

					<description><![CDATA[<p>Simulink contains undocumented public API for access to its data dictionary functionality. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/simulink-data-dictionary">Simulink Data Dictionary</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/improving-simulink-performance" rel="bookmark" title="Improving Simulink performance">Improving Simulink performance </a> <small>Simulink simulation run-time performance can be improved by orders of magnitude by following some simple steps. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/sparse-data-math-info" rel="bookmark" title="Sparse data math info">Sparse data math info </a> <small>Matlab contains multiple libraries for handling sparse data. These can report very detailed internal info. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips" rel="bookmark" title="Controlling plot data-tips">Controlling plot data-tips </a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again I wish to welcome guest blogger <a target="_blank" rel="nofollow" href="http://aetoolbox.com">Donn Shull</a>. Donn has previously written a series of articles on Matlab&#8217;s previous-generation class-object system (<a target="_blank" href="/?s=UDD">UDD</a>). Today Donn explores a little-known yet quite useful aspect of Simulink.</i></p>
<h3 id="Introduction">Introduction</h3>
<p>In 2014, MathWorks introduced the Simulink Data Dictionary. This new feature provides the ability to store <code>Data Types</code>, <code>Parameters</code>, and <code>Signals</code> in database files. This is great news for embedded systems developers who want the flexibility of using data objects and want to avoid using the base workspace with its potential for data corruption.<br />
In its initial implementation, the data dictionary interface is provided by the <a target="_blank" rel="nofollow" href="https://www.mathworks.com/help/simulink/ug/search-and-edit-using-model-explorer.html">Simulink Model Explorer</a>. The GUI interface is clean, intuitive, and easy to use. This interface supports importing and exporting dictionaries to m files and mat files.<br />
Unfortunately, in production code generation environments there is frequently a need to interface this data with external tools such as software specification systems, documentation generators, and calibration tools. MathWorks have not published an API for accessing dictionaries from code, indicating that it may possibly be available in a future release. Today, we will look at some portions of the undocumented API for Simulink Data Dictionaries.<br />
<center><a target="_blank" rel="nofollow" href="https://web.archive.org/web/20150402031355im_/http://www.mathworks.com/help/simulink/ug/importfrombws.png"><img decoding="async" alt="Simulink F14 model using data dictionary" src="https://web.archive.org/web/20150402031355im_/http://www.mathworks.com/help/simulink/ug/importfrombws.png" title="Simulink F14 model using data dictionary" width="100%" style="max-width: 700px;" /></a></center><br />
<span id="more-5571"></span></p>
<h3 id="background">Some background information</h3>
<p>Simulink Data Dictionaries exist as files having a standard file extension of <i>.sldd</i>. Dictionary files can be opened with the <i><b>open</b></i> function, which in turn calls <i><b>opensldd</b></i>. This opens the file and launches the Simulink Model Explorer with the selected dictionary node. When a dictionary is opened, a cached copy is created. While working with a dictionary, changes are made to the cached copy. The dictionary file is only changed when the changes are saved by issuing the relevant command. Until the cached copy is saved, it is possible to view differences between the file and the cached copy, and revert any unwanted changes. The file maintains the date, time, and author of the last saved change, but no information about previous revisions.<br />
From the Model Explorer it is possible to add items to a dictionary from a model, the base workspace, or by creating new items. We can associate a Simulink model with a dictionary by using the model properties dropdown in the Simulink editor.<br />
Using data dictionaries it is possible to tailor a model&#8217;s code generation for different targets, simply by changing the dictionary that is being used.</p>
<h3 id="API">The Simulink Data Dictionary API</h3>
<p>Programmatic access to Simulink Data Dictionaries is provided by the undocumented MCOS package <code>Simulink.dd</code>. We will look at two package functions and a few methods of the <code>Simulink.dd.Connection</code> class. These provide the basic ability to work with dictionaries from within our m code.</p>
<h4 id="create">Creating and Opening Dictionary Files</h4>
<p>Dictionary files are created with the package function <i>create</i>:</p>
<pre lang='matlab'>hDict = Simulink.dd.create(dictionaryFileName);</pre>
<p>Existing dictionary files are opened using the package function <i>open</i>:</p>
<pre lang='matlab'>hDict = Simulink.dd.open(dictionaryFileName);</pre>
<p>In both cases the functions return a handle of type <code>Simulink.dd.Connection</code> to the named dictionary file.</p>
<h4 id="modify">Modifying a Dictionary</h4>
<p>We can use methods of the <code>Simulink.dd.Connection</code> instance to modify an open dictionary. Dictionaries are organized into two sections: The <code>Configurations</code> section contains <code>Simulink.ConfigSet</code> entries, while <code>Parameter</code>, <code>Signal</code>, and <code>DataType</code> items are placed in the <code>Global</code> section. We can get a list of the items in a section using the <i>getChildNames</i> method:</p>
<pre lang='matlab'>childNamesList = hDict.getChildNames(sectionName);</pre>
<p>Adding and removing items from a section are done using the <i>insertEntry</i> and <i>deleteEntry</i> methods, respectively:</p>
<pre lang='matlab'>
hDict.insertEntry(sectionName, entryName, object)
hDict.deleteEntry(sectionName, entryName)
</pre>
<p>Modifying an existing entry is done using the <i>getEntry</i>, and <i>setEntry</i> methods:</p>
<pre lang='matlab'>
workingCopy = hDict.getEntry(sectionName.entryName)
% modify workingCopy
hDict.setEntry(sectionName.entryName, workingCopy)
</pre>
<p>A collection of objects from the base workspace can be added to a dictionary using the <i>importFromBaseWorkspace</i> method:</p>
<pre lang='matlab'>hDict.importFromBaseWorkspace(sectionName, overwriteExisitngObjectsFlag, deleteFromBaseWorkspaceFlag, cellArrayOfNames)</pre>
<p>Additional dictionary manipulations are possible using the <i>evalin</i> and <i>assignin</i> methods:</p>
<pre lang='matlab'>
hDict.evalin(commandString)
hDict.assignin(variableName, variable)
</pre>
<h4 id="close">Closing a Dictionary</h4>
<p>Finalizing a dictionary session is done with the <i>saveChanges</i>, <i>close</i>, and <i>delete</i> methods:</p>
<pre lang='matlab'>
hDict.saveChanges
hDict.close
hDict.delete
</pre>
<h3 id="example">Example: Migrate Single Model to Use Dictionary</h3>
<p>This example is an adaptation of <a target="_blank" rel="nofollow" href="https://www.mathworks.com/help/simulink/ug/migrate-models-to-use-dictionary.html">MathWorks&#8217; interactive example of the same title</a>, using programmatic Matlab commands rather than GUI interactions.</p>
<ol>
<li>Start by using <i><b>load_system</b></i> to open the f14 model. This opens the model and executes the <i>PreLoadFcn</i> callback, which loads design data into the base workspace, without opening the Simulink block diagram editor:
<pre lang='matlab'>load_system('f14');</pre>
</li>
<li>Use the Simulink package function <i>findVars</i> to find the variables used by the model:
<pre lang='matlab'>usedVariables = Simulink.findVars('f14');</pre>
</li>
<li>Next, use the <i>create</i> package function to create and open a new Simulink Data Dictionary:
<pre lang='matlab'>hDict = Simulink.dd.create('f14_data_dictionary.sldd');</pre>
</li>
<li>Attach the newly created dictionary to the model:
<pre lang='matlab'>set_param('f14', 'DataDictionary', 'f14_data_dictionary.sldd');</pre>
</li>
<li>Use one of the API methods to add these variables to the Data Dictionary:
<pre lang='matlab'>
overWrite = true;
deleteFromWorkspace = false;
for n = 1:numel(usedVariables)
    if strcmp(usedVariables(n).Source, 'base workspace')
        hDict.importFromBaseWorkspace(overWrite, deleteFromWorkspace, {usedVariables(n).Name});
    end
end
</pre>
</li>
<li>Save the changes made to the dictionary:
<pre lang='matlab'>hDict.saveChanges;</pre>
</li>
<li>Clean up and we are done:
<pre lang='matlab'>
hDict.close;
hDict.delete;
clear hDict;
</pre>
</li>
</ol>
<h3 id="notes">Final notes</h3>
<p>MathWorks have recognized the value of data dictionaries for a long time. In 2006, MathWorker Tom Erkkinen <a target="_blank" rel="nofollow" href="http://www.eetimes.com/document.asp?doc_id=1272777">published a paper</a> about multitarget modeling using data dictionaries. The <code>Simulink.dd</code> package was added to Matlab in R2011b, and the <code>DataDictionary</code> parameter was added to Simulink models in R2012a. MathWorks have also <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/153367-how-to-eval-expressions-in-simulink-data-dictionaries">indicated</a> that a user API for Simulink Data Dictionaries may be in the works. Until it is released we can make do with the undocumented API.<br />
<b><u>Update March 7, 2015</u></b>: Matlab release R2015a now includes a fully documented <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/slref/simulink.data.dictionary-class.html"><code>Simulink.data.Dictionary</code></a> class, which works in a very similar manner. Users of R2015a or newer should use this new <code>Simulink.data.Dictionary</code> class, while users of previous Matlab releases can use the <code>Simulink.dd</code> class presented in this article.<br />
Have you made some good use of this data-dictionary functionality in your project? If so, please share your experience in a comment below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/simulink-data-dictionary">Simulink Data Dictionary</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/improving-simulink-performance" rel="bookmark" title="Improving Simulink performance">Improving Simulink performance </a> <small>Simulink simulation run-time performance can be improved by orders of magnitude by following some simple steps. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/sparse-data-math-info" rel="bookmark" title="Sparse data math info">Sparse data math info </a> <small>Matlab contains multiple libraries for handling sparse data. These can report very detailed internal info. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips" rel="bookmark" title="Controlling plot data-tips">Controlling plot data-tips </a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/simulink-data-dictionary/feed</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
			</item>
		<item>
		<title>Improving Simulink performance</title>
		<link>https://undocumentedmatlab.com/articles/improving-simulink-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=improving-simulink-performance</link>
					<comments>https://undocumentedmatlab.com/articles/improving-simulink-performance#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 12 Feb 2014 16:00:32 +0000</pubDate>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Simulink]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4641</guid>

					<description><![CDATA[<p>Simulink simulation run-time performance can be improved by orders of magnitude by following some simple steps. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/improving-simulink-performance">Improving Simulink performance</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/improving-fwrite-performance" rel="bookmark" title="Improving fwrite performance">Improving fwrite performance </a> <small>Standard file writing performance can be improved in Matlab in surprising ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/improving-save-performance" rel="bookmark" title="Improving save performance">Improving save performance </a> <small>There are many different ways of improving Matlab's standard save function performance. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/simulink-data-dictionary" rel="bookmark" title="Simulink Data Dictionary">Simulink Data Dictionary </a> <small>Simulink contains undocumented public API for access to its data dictionary functionality. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/improving-graphics-interactivity" rel="bookmark" title="Improving graphics interactivity">Improving graphics interactivity </a> <small>Matlab R2018b added default axes mouse interactivity at the expense of performance. Luckily, we can speed-up the default axes. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few days ago I happened to speak with a colleague about Simulink run-time performance, and we discussed various ideas for simulation speed-up. This topic is very important to MathWorks, as evidenced by a dedicated <a target="_blank" rel="nofollow" href="http://mathworks.com/help/simulink/#performance">documentation section</a>, newsletter articles (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/newsletters/articles/improving-simulation-performance-in-simulink.html">1</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/newsletters/articles/improving-simulink-design-optimization-performance-using-parallel-computing.html">2</a>), webinars (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/videos/speeding-up-simulink-applications-81795.html">1</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/videos/speeding-up-simulations-with-parallel-computing-81752.html">2</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/videos/speeding-up-simulink-for-control-systems-applications-81736.html">3</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/videos/speeding-up-simulink-for-signal-processing-applications-81748.html">4</a>) and <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/category/performance/">multiple blog posts</a> on improving simulation performance using the Simulink product.<br />
<span class="alignright"><img decoding="async" src="https://undocumentedmatlab.com/images/faster.jpg" width="150" height="127"/></span>This blog covers mainly the Matlab core product and closely-related toolboxes. However, since the various suggestions for improving performance are spread across so many resources, I thought that it would be worthwhile to create a post listing all the suggestions in a single place. When faced with a slow simulation, it&#8217;s nice to know that there are so many available speed-up options, so I hope readers will find it useful. Note that these suggestions are in the large part fully documented and supported. The ideas are listed based on semantic relationship, and not by order of importance:<br />
<span id="more-4641"></span></p>
<ul>
<li>Select <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/acceleration.html">Accelerator or Rapid Accelerator</a> simulation mode (also <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/ug/comparing-performance.html">see here</a>)</li>
<li>Enable the options for Compiler optimization, automatic Block Reduction and others in the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/gui/optimization-pane-general.html">Optimization pane</a> of the Configuration Parameters window.</li>
<li>Switch the <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2010/10/28/tips-for-simulation-performance/">Compiler optimization</a> from <i>faster build</i> to <i>faster run</i>.</li>
<li>Disable the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/gui/simulation-target-pane-general.html">options</a> for debugging/animation support, overflow detection and echoing expressions without semicolons  in the Simulation Target pane of the Configuration Parameters window. Note that overflow detection is important for fixed-point data so if your model includes FP data, keep this option enabled.</li>
<li>Disable <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/stateflow/ug/speeding-up-simulation.html">similar configuration options</a> in Stateflow’s Configuration Parameters window (which is similar but separate from the Simulink window).</li>
<li>Keep Stateflow charts and Simulink blocks/models closed during simulation to prevent run-time updates (this relates to the animation feature, if enabled)</li>
<li>Keep <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/ug/scope-signal-viewer-characteristics.html">output scopes</a> closed during simulation run-time; open the scopes only after the simulation ends. If a scope must remain open in run-time, reduce the number of data points (via decimation, reduced time range and reduced number of plotted signals), increase the plotting refresh period, disable scope scrolling, remove data markers and legends, limit the history size, and use reduced fidelity in the viewer parameters. A similar recommendation applies to regular Matlab plots, by the way.</li>
<li>Vectorize processing by combining multiple signals into a vector and applying the processing on the vector rather than on the separate signals.</li>
<li>Sample data in <a target="_blank" rel="nofollow" href="http://mathworks.com/help/dsp/ug/sample-and-frame-based-concepts.html">batches</a> (rather than one-by-one) using frame-based processing (<a target="_blank" rel="nofollow" href="http://mathworks.com/help/dsp/release-notes.html#bs1rpr_-1">R2011b and newer</a>). This can speed up simulations by 10x or more, at the expense of just a little extra memory.</li>
<li>Aggregate small blocks into larger ones.</li>
<li><a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2010/10/28/tips-for-simulation-performance/">Load the model in memory</a> using <i><b>load_system</b></i> instead of <i><b>open_system</b></i> and simulate it using the <i><b>sim</b></i> command, then post process/display the outputs.</li>
<li><a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2010/10/28/tips-for-simulation-performance/">Avoid</a> blocks that do not support code generation, since they would have to be run in slower interpreted mode.</li>
<li>If your simulation does not use linear algebra (matrix arithmetic), disable BLAS library support  in the Simulation Target pane. But if it does use it, then ensure that BLAS is enabled for optimal performance.</li>
<li><a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2010/10/28/tips-for-simulation-performance/">Avoid</a> algebraic loops where possible.</li>
<li><a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2010/10/28/tips-for-simulation-performance/">Avoid</a> <code>Matlab S-Function</code> and <code>Interpreted Matlab Function</code> blocks. Instead, use <code>Matlab Function</code>, <code>System</code> and <code>C-MEX</code> blocks.<br />
 &nbsp; </p>
<p />
Note: IMHO, the naming of these blocks is quite confusing: <code>Matlab Function</code> refers to a subset of the Matlab language previously called <code>Embedded Matlab</code> that can be directly converted into C-code without requiring the Matlab run-time (MCR); this is basically the language subset used by the Matlab Coder Toolbox. <code>Interpreted Matlab Function</code> refers to the full Matlab functionality and requires the Matlab run-time (MCR) – it was previously called <code>Matlab Function</code>.</li>
<li>Reduce, simplify or eliminate initialization and termination phases.</li>
<li>Use the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/gui/mask-editor-overview.html">Mask Editor</a> to reduce block images resolution and size.</li>
<li>Store configurations in <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/file-opening-loading-and-saving.html">loadable MAT files</a> rather than programmatically.</li>
<li>Consolidate multiple <i><b>set_param</b></i> calls into a single call having several name / value pairs.</li>
<li>Use a stronger platform (esp. increase the amount of memory).</li>
<li><a target="_blank" rel="nofollow" href="http://www.linkedin.com/groups/Hi-Im-using-simulink-process-109866.S.192318533?view=&#038;gid=109866&#038;item=192318533">Limit or disable log output</a>, and disk I/O in general.</li>
<li>Use the <i><b>sldiagnostics</b></i> and <i><b>slprofreport</b></i> functions and the <a target="_blank" rel="nofollow" href="https://www.mathworks.com/help/simulink/ug/how-profiler-captures-performance-data.html">Simulink Profiler</a>, to identify and eliminate simulation bottlenecks.</li>
<li>Use the <i><b>performanceadvisor</b></i> function and the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/automatic-performance-optimization.html">Simulink Model Performance Advisor</a> to automatically adjust model configurations for best performance (<a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2012/11/21/automatically-improving-model-performance/">R2012b and newer</a>; also see <a target="_blank" rel="nofollow" href="http://www.mathworks.com/videos/simulation-analysis-and-performance-74976.html">this webinar</a>).</li>
<li>Manually adjust model solver parameters for optimal performance, based on a-priori knowledge about the model behavior.</li>
<li>Use a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/gads/choose-a-solver.html">faster solver</a> that can still process the model. Different models may require different solvers to run optimally (also see <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/releases/R2012a/toolbox/simulink/ug/f11-69449.html">here</a>).</li>
<li><a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2012/06/04/the-most-useful-command-for-debugging-variable-step-solver-performance/">Tune solver parameters</a> (decrease solver order, increase step size  and error tolerance) to improve solution convergence speed at the expense of some accuracy. One user <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2012/06/04/the-most-useful-command-for-debugging-variable-step-solver-performance/#comment-1850">reported</a> a 20x speedup by simply increasing the step-size.</li>
<li>Prevent <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2013/04/26/zero-crossing-detection-what-are-your-options/">excessive zero-crossing</a> or disable zero-crossing detection (also see <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/ug/simulating-dynamic-systems.html#bridiag-5">here</a> and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/stateflow/ug/when-to-enable-zero-crossing-detection.html">here</a>).</li>
<li>Use simpler models or models with reduced fidelity.</li>
<li><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/ug/saving-and-restoring-the-simulation-state-as-the-simstate.html">Store the simulation state</a> at specific points, then load these states for repeated later simulations, thus saving the simulation time of the loaded portion.</li>
<li><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/ug/running-parallel-simulations.html">Run simulations in parallel</a> using Parallel Computing Toolbox (also see <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/newsletters/articles/improving-simulink-design-optimization-performance-using-parallel-computing.html">here</a>, <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2009/03/31/parallel-computing-with-simulink-model-reference-builds/">here</a> and <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2010/10/17/parallel-computing-with-simulink-running-thousands-of-simulations/">here</a>). An <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/seth/2010/10/28/tips-for-simulation-performance/">easy way to do this</a> is to run the <i><b>sim</b></i> command within a <i><b>parfor</b></i> loop.</li>
<li><a target="_blank" rel="nofollow" href="http://www.linkedin.com/groups/Hi-Im-using-simulink-process-109866.S.192318533?view=&#038;gid=109866&#038;item=192318533">Move some calculations</a> onto FPGA or GPU.</li>
<li>Use a real-time system and set simulation speed to real-time (high priority).</li>
</ul>
<p>Some additional ideas can be found in the blog posts and webinars mentioned in the hyperlinks at the top of this post. One of the newsletter articles <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/newsletters/articles/improving-simulation-performance-in-simulink.html">concludes</a> with an example of how applying some of these techniques to a specific model resulted in reduced simulation time, from 453 down to 5 seconds.<br />
I would like to take this opportunity to congratulate MathWorks on a job well done with Simulink&#8217;s Performance Advisor. I expect a variant of this tool to be available for regular Matlab m-code in some future Matlab release; it would blend in nicely with the existing mlint (Code Analyzer) tool.</p>
<h3 id="course">Advanced Matlab Programming course – London 10-11 March, 2014</h3>
<p>If this topic has piqued your interest, consider joining my <a target="_blank" href="/training/advanced-matlab-seminars-london-10-14-march-2014/">Advanced Matlab Programming course</a> in London on 10-11 March, 2014. In this course/seminar I will explore numerous other ways by which we can improve Matlab’s performance and create professional code. This is a unique opportunity to take your Matlab skills to a higher level within a couple of days.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/improving-simulink-performance">Improving Simulink performance</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/improving-fwrite-performance" rel="bookmark" title="Improving fwrite performance">Improving fwrite performance </a> <small>Standard file writing performance can be improved in Matlab in surprising ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/improving-save-performance" rel="bookmark" title="Improving save performance">Improving save performance </a> <small>There are many different ways of improving Matlab's standard save function performance. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/simulink-data-dictionary" rel="bookmark" title="Simulink Data Dictionary">Simulink Data Dictionary </a> <small>Simulink contains undocumented public API for access to its data dictionary functionality. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/improving-graphics-interactivity" rel="bookmark" title="Improving graphics interactivity">Improving graphics interactivity </a> <small>Matlab R2018b added default axes mouse interactivity at the expense of performance. Luckily, we can speed-up the default axes. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/improving-simulink-performance/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Reading non-Latin text files</title>
		<link>https://undocumentedmatlab.com/articles/reading-non-latin-text-files?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=reading-non-latin-text-files</link>
					<comments>https://undocumentedmatlab.com/articles/reading-non-latin-text-files#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 28 Sep 2011 14:51:50 +0000</pubDate>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Simulink]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2447</guid>

					<description><![CDATA[<p>A workaround that enables reading non-Latin text files in Matlab is shown</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/reading-non-latin-text-files">Reading non-Latin text files</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/fig-files-format" rel="bookmark" title="FIG files format">FIG files format </a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/command-window-text-manipulation" rel="bookmark" title="Command Window text manipulation">Command Window text manipulation </a> <small>Special control characters can be used to format text output in Matlab's Command Window. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/another-command-window-text-color-hack" rel="bookmark" title="Another Command Window text color hack">Another Command Window text color hack </a> <small>Matlab's fprintf command has an undocumented hack to display orange-colored text. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/bold-color-text-in-the-command-window" rel="bookmark" title="Bold color text in the Command Window">Bold color text in the Command Window </a> <small>Matlab Command Window text can be formatted *bold* since R2011b. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>In the spirit of the Jewish New Year that begins tonight, I would like to share a workaround that I received from blog reader Ro&#8217;ee Gilron of Tel-Aviv University:<br />
Matlab users who use non-Latin computer Locales are aware of the issues that the Matlab Command Window has had with such languages for many years. I am not sure whether these problems are due to the LTR nature of Hebrew/Arabic, or their use of a non-supported code-page, or some other reason. To this day (R2011b), I am not aware of any fix or workaround for these issues.<br />
But it seems that in addition, Matlab has a problem reading files that contain text in these languages, even when the computer&#8217;s Locale is set correctly, to a Locale that supports the non-Latin text. This is where Ro&#8217;ee&#8217;s workaround helps. In his words:<br />
<q><i>To give some more background, this used to work with a 32bit system, and an older version of Matlab (7.1). Now it doesn&#8217;t. Saving the file in UTF-8 and using <b>fopen</b> and <b>textscan</b> instead of <b>importdata</b> gives me this:<br />
nowords =<br />
    &#8216;ï»¿×©×œ×‘×§&#8217;<br />
    &#8216;×”×ª×œ×›×‘&#8217;<br />
    &#8216;× ×™×›×˜×¨&#8217;<br />
    &#8216;×ª×œ×¤×•×¨×©&#8217;<br />
    &#8216;×œ×§×˜× &#8216;<br />
    &#8216;×ž×–×•×—×©&#8217;<br />
    &#8216;×©×œ×˜×™×§&#8217;<br />
    &#8216;×˜×™×‘×¨&#8217;<br />
    &#8216;×¢×•×œ×’&#8217;<br />
    &#8216;×¡×œ×‘×•×—×“&#8217;<br />
    &#8216;×ž×©×•×—×’×•×ª&#8217;<br />
    &#8216;×ž×œ×•×’×¡×•×ª&#8217;<br />
    &#8216;×¡×‘×§&#8217;<br />
    &#8216;×¦×ž×©×¨&#8217;<br />
    &#8216;×”×›×¨×™×‘&#8217;<br />
    &#8216;×ª×ž×¦×™×œ&#8217;<br />
</i></q><br />
The solution is as follows (requires Simulink):<br />
1) Change system Locale to Hebrew: <a target="_blank" rel="nofollow" href="http://windows.microsoft.com/en-US/windows7/Change-the-system-locale">http://windows.microsoft.com/en-US/windows7/Change-the-system-locale</a><br />
(this doesn’t change the language of the OS etc.).<br />
2) Change the encoding that Matlab uses:<br />
<a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/toolbox/simulink/slref/slcharacterencoding.html">http://www.mathworks.com/help/toolbox/simulink/slref/slcharacterencoding.html</a><br />
They tell you not to, but I did&#8230; &#8211; you must change it to encoding that works for Hebrew: <a target="_blank" rel="nofollow" href="http://www.iana.org/assignments/character-sets">http://www.iana.org/assignments/character-sets</a><br />
Any other language should work as well (I hope&#8230;). For Hebrew the code that works for me is ISO_8859-8<br />
3) You should now be able to read TXT files that have Hebrew characters in them.</p>
<pre lang="matlab">
>> a='הצלחה!'
a =
!
>> currentCharacterEncoding = slCharacterEncoding();
>> currentCharacterEncoding = get_param(0, 'CharacterEncoding')  % equivalent alternative
currentCharacterEncoding =
windows-1252
% Now modify the default encoding to something more useful
>> slCharacterEncoding('ISO_8859-8')
>> set_param(0, 'CharacterEncoding', 'ISO_8859-8');   % equivalent alternative
>> currentCharacterEncoding = slCharacterEncoding()
currentCharacterEncoding =
ISO-8859-8
>> a='הצלחה!'
a =
!                  % still no good in the Command Window...
% Let's try to read a file with some Hebrew words:
>> neutral = importdata('neutral.txt')
neutral =
שולחן'
    'כסא'
    'מנורה'
    'צלחת'
    'סיר'
    'מזלג'
</pre>
<p>So, it appears that while we did not solve the problems with the Command Window, at least we can now read the prayer book for our New Year prayers&#8230;<br />
Let this be a year of fulfillment, prosperity, health and happiness to all. <i><b>Shana Tova everybody!</b></i></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/reading-non-latin-text-files">Reading non-Latin text files</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/fig-files-format" rel="bookmark" title="FIG files format">FIG files format </a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/command-window-text-manipulation" rel="bookmark" title="Command Window text manipulation">Command Window text manipulation </a> <small>Special control characters can be used to format text output in Matlab's Command Window. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/another-command-window-text-color-hack" rel="bookmark" title="Another Command Window text color hack">Another Command Window text color hack </a> <small>Matlab's fprintf command has an undocumented hack to display orange-colored text. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/bold-color-text-in-the-command-window" rel="bookmark" title="Bold color text in the Command Window">Bold color text in the Command Window </a> <small>Matlab Command Window text can be formatted *bold* since R2011b. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/reading-non-latin-text-files/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
