<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://qetlab.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Update_odometer</id>
	<title>Update odometer - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://qetlab.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Update_odometer"/>
	<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=Update_odometer&amp;action=history"/>
	<updated>2026-10-06T22:15:43Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=Update_odometer&amp;diff=747&amp;oldid=prev</id>
		<title>Nathaniel: Created page with &quot;{{Function |name=update_odometer |desc=Increases a vector subject to limits on how large each entry can be |upd=December 11, 2014 |cat=List of functions#Helper_functions|Hel...&quot;</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=Update_odometer&amp;diff=747&amp;oldid=prev"/>
		<updated>2015-01-14T20:11:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Function |name=update_odometer |desc=Increases a vector subject to limits on how large each entry can be |upd=December 11, 2014 |cat=List of functions#Helper_functions|Hel...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Function&lt;br /&gt;
|name=update_odometer&lt;br /&gt;
|desc=Increases a vector subject to limits on how large each entry can be&lt;br /&gt;
|upd=December 11, 2014&lt;br /&gt;
|cat=[[List of functions#Helper_functions|Helper functions]]&lt;br /&gt;
|helper=1}}&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;#039;&amp;#039;&amp;#039;update_odometer&amp;#039;&amp;#039;&amp;#039;&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that implements an &amp;quot;odometer&amp;quot;: that is, it increases the right-most entry of a vector by 1. If that right-most entry is now larger than its maximum allowed value then it &amp;quot;rolls over&amp;quot; to 0 and the second-to-right-most entry increases by 1. Similarly, if this entry is now too larger, it rolls over, and so on.&lt;br /&gt;
&lt;br /&gt;
This function is useful if you are in a situation where you want to nest multiple &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; loops, but you don&amp;#039;t know beforehand exactly how many of them there will be (since it depends on user input, for example).&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;NEW_IND = update_odometer(OLD_IND,UPPER_LIM)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;OLD_IND&amp;lt;/tt&amp;gt;: The vector to be updated.&lt;br /&gt;
* &amp;lt;tt&amp;gt;UPPER_LIM&amp;lt;/tt&amp;gt;: A vector of the same length as &amp;lt;tt&amp;gt;OLD_IND&amp;lt;/tt&amp;gt; with the property that its &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;-th entry specifies the &amp;quot;roll over&amp;quot; value of the &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;-th entry of &amp;lt;tt&amp;gt;OLD_IND&amp;lt;/tt&amp;gt;. That is, the &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;-th value of &amp;lt;tt&amp;gt;OLD_IND&amp;lt;/tt&amp;gt; is constrained to being in the interval from &amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;UPPER_LIM(j)-1&amp;lt;/tt&amp;gt; (inclusive).&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
The following code loops over all vectors of length 2 with the property that their first entry is 0, 1, or 2, and their second entry is 0 or 1:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; v = [0,0]; upper_lim = [3,2];&lt;br /&gt;
&amp;gt;&amp;gt; for j = 0:prod(upper_lim)-1&lt;br /&gt;
     v = update_odometer(v,upper_lim)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
v =&lt;br /&gt;
&lt;br /&gt;
     0     1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
v =&lt;br /&gt;
&lt;br /&gt;
     1     0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
v =&lt;br /&gt;
&lt;br /&gt;
     1     1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
v =&lt;br /&gt;
&lt;br /&gt;
     2     0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
v =&lt;br /&gt;
&lt;br /&gt;
     2     1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
v =&lt;br /&gt;
&lt;br /&gt;
     0     0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{SourceCode|name=update_odometer|helper=1}}&lt;/div&gt;</summary>
		<author><name>Nathaniel</name></author>
	</entry>
</feed>