<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Vectorizing the Notion of Colon (:)</title>
	<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/</link>
	<description>Loren Shure  works on design of the MATLAB language at &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62;. She writes here about once a week on MATLAB programming and related topics. &#60;br&#62;&#60;br&#62;&#60;a href="/images/loren-full.jpg"&#62;&#60;img src="/images/loren.jpg"&#62;&#60;/a&#62;</description>
	<pubDate>Mon, 23 Nov 2009 01:47:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29839</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 04 Nov 2008 11:03:46 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29839</guid>
		<description>Walter-

You can use "end" in some expressions, IF the expressions are used for indexing into an array as Doug's expression does.  In my tests up above, you can't use "end" because I am simply generating the sequence without indexing.  In addition, Doug's works because the value of "end" in that context is possible for MATLAB to ascertain.  I think many, perhaps all, of the other solutions don't have the indexing context explicit enough at the call site for MATLAB to discern the meaning of "end".

--Loren

--Loren</description>
		<content:encoded><![CDATA[<p>Walter-</p>
<p>You can use &#8220;end&#8221; in some expressions, IF the expressions are used for indexing into an array as Doug&#8217;s expression does.  In my tests up above, you can&#8217;t use &#8220;end&#8221; because I am simply generating the sequence without indexing.  In addition, Doug&#8217;s works because the value of &#8220;end&#8221; in that context is possible for MATLAB to ascertain.  I think many, perhaps all, of the other solutions don&#8217;t have the indexing context explicit enough at the call site for MATLAB to discern the meaning of &#8220;end&#8221;.</p>
<p>&#8211;Loren</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Walter Roberson</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29837</link>
		<dc:creator>Walter Roberson</dc:creator>
		<pubDate>Mon, 03 Nov 2008 22:29:09 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29837</guid>
		<description>A problem with the given solutions is that they do not handle the 'end' operator -- a strange operator that contextually knows what the appropriate limits are for each dimension.

http://groups.google.ca/group/comp.soft-sys.matlab/browse_thread/thread/c1ef54d585340aea/00766f55e26eaf6c

Doug Schwarz wrote:
&#62;   b = a(:,setdiff(1:end,1));

which unexpectedly works, and I explored why this is unexpected (and hence why no user-level routine can
duplicate the meaning of 'end')</description>
		<content:encoded><![CDATA[<p>A problem with the given solutions is that they do not handle the &#8216;end&#8217; operator &#8212; a strange operator that contextually knows what the appropriate limits are for each dimension.</p>
<p><a href="http://groups.google.ca/group/comp.soft-sys.matlab/browse_thread/thread/c1ef54d585340aea/00766f55e26eaf6c" rel="nofollow">http://groups.google.ca/group/comp.soft-sys.matlab/browse_thread/thread/c1ef54d585340aea/00766f55e26eaf6c</a></p>
<p>Doug Schwarz wrote:<br />
&gt;   b = a(:,setdiff(1:end,1));</p>
<p>which unexpectedly works, and I explored why this is unexpected (and hence why no user-level routine can<br />
duplicate the meaning of &#8216;end&#8217;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucio</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29822</link>
		<dc:creator>Lucio</dc:creator>
		<pubDate>Tue, 21 Oct 2008 17:30:27 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29822</guid>
		<description>I am not sure if this is bullet proof for all the cases, but I usually write something like this for this type of problems:

len = max(max(starts),max(ends))+1;

find(cumsum(accumarray(starts',1,[len,1])-accumarray(ends'+1,1,[len,1])))

Lucio</description>
		<content:encoded><![CDATA[<p>I am not sure if this is bullet proof for all the cases, but I usually write something like this for this type of problems:</p>
<p>len = max(max(starts),max(ends))+1;</p>
<p>find(cumsum(accumarray(starts&#8217;,1,[len,1])-accumarray(ends&#8217;+1,1,[len,1])))</p>
<p>Lucio</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Fig</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29814</link>
		<dc:creator>Matt Fig</dc:creator>
		<pubDate>Wed, 15 Oct 2008 20:00:22 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29814</guid>
		<description>Rather than go too off topic (against Loren's rules!), I created a thread on the newsreader that addresses my question.  Anyone who is interested may find it here:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/237608</description>
		<content:encoded><![CDATA[<p>Rather than go too off topic (against Loren&#8217;s rules!), I created a thread on the newsreader that addresses my question.  Anyone who is interested may find it here:</p>
<p><a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/237608" rel="nofollow">http://www.mathworks.com/matlabcentral/newsreader/view_thread/237608</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29813</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 15 Oct 2008 01:32:58 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29813</guid>
		<description>Tom-

Nice contribution!

Matt-

Check out bsxfun.  I've talked about it in the blog once or twice.

--Loren</description>
		<content:encoded><![CDATA[<p>Tom-</p>
<p>Nice contribution!</p>
<p>Matt-</p>
<p>Check out bsxfun.  I&#8217;ve talked about it in the blog once or twice.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Fig</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29812</link>
		<dc:creator>Matt Fig</dc:creator>
		<pubDate>Tue, 14 Oct 2008 21:30:07 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29812</guid>
		<description>I am often in need of vectorizing an operator where the inputs aren't the same size.  This seems more challenging to me.  For instance:  given an array MAT = M(IDX) and a vector of unique values M, find IDX.  This involves the == operator with different length inputs.  The for loop approach is straightforward: 

function [IDX] = getidx(MAT,M)
% Given MAT = M(IDX) and M, this finds IDX.
% Where length(unique(M)) = length(M).

IDX = zeros(size(MAT));

for ii = 1:length(M)
    IDX(MAT==M(ii)) = ii;
end


I am at a loss to vectorize this, perhaps I just need more sleep :)</description>
		<content:encoded><![CDATA[<p>I am often in need of vectorizing an operator where the inputs aren&#8217;t the same size.  This seems more challenging to me.  For instance:  given an array MAT = M(IDX) and a vector of unique values M, find IDX.  This involves the == operator with different length inputs.  The for loop approach is straightforward: </p>
<p>function [IDX] = getidx(MAT,M)<br />
% Given MAT = M(IDX) and M, this finds IDX.<br />
% Where length(unique(M)) = length(M).</p>
<p>IDX = zeros(size(MAT));</p>
<p>for ii = 1:length(M)<br />
    IDX(MAT==M(ii)) = ii;<br />
end</p>
<p>I am at a loss to vectorize this, perhaps I just need more sleep :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Richardson</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29811</link>
		<dc:creator>Tom Richardson</dc:creator>
		<pubDate>Tue, 14 Oct 2008 19:20:38 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29811</guid>
		<description>Note that the one line solutions easily generalize to variable increments, e.g.,

&#62;&#62; coloncatshort = @(starts,steps,ends) cell2mat(arrayfun(@(a,b,c) {a:b:c},starts,steps,ends))
coloncatshort = 
    @(starts,steps,ends)cell2mat(arrayfun(@(a,b,c){a:b:c},starts,steps,ends))
&#62;&#62; coloncatshort([1 3 2],[4 4 2],[5 7 8])
ans =
     1     5     3     7     2     4     6     8</description>
		<content:encoded><![CDATA[<p>Note that the one line solutions easily generalize to variable increments, e.g.,</p>
<p>&gt;&gt; coloncatshort = @(starts,steps,ends) cell2mat(arrayfun(@(a,b,c) {a:b:c},starts,steps,ends))<br />
coloncatshort =<br />
    @(starts,steps,ends)cell2mat(arrayfun(@(a,b,c){a:b:c},starts,steps,ends))<br />
&gt;&gt; coloncatshort([1 3 2],[4 4 2],[5 7 8])<br />
ans =<br />
     1     5     3     7     2     4     6     8</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29810</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 14 Oct 2008 12:18:17 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29810</guid>
		<description>Nice additional algorithms, everyone!

Daniel,
This article does not imply any changes to the colon operator, or even the introduction of such a function into MATLAB.  We will always consider requests along these lines if we hear enough from customers.

--Loren</description>
		<content:encoded><![CDATA[<p>Nice additional algorithms, everyone!</p>
<p>Daniel,<br />
This article does not imply any changes to the colon operator, or even the introduction of such a function into MATLAB.  We will always consider requests along these lines if we hear enough from customers.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Armyr</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29809</link>
		<dc:creator>Daniel Armyr</dc:creator>
		<pubDate>Tue, 14 Oct 2008 12:01:46 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29809</guid>
		<description>Hi.
When reading the article I realize i didn't quite understand the actual problem. Now that I do understand it, I wonder if this means that there will be plans to update the colon() to allow array inputs? Right now it seems it takes the very first value fo any array input and ignores the rest.

--DA</description>
		<content:encoded><![CDATA[<p>Hi.<br />
When reading the article I realize i didn&#8217;t quite understand the actual problem. Now that I do understand it, I wonder if this means that there will be plans to update the colon() to allow array inputs? Right now it seems it takes the very first value fo any array input and ignores the rest.</p>
<p>&#8211;DA</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan</title>
		<link>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29808</link>
		<dc:creator>Stefan</dc:creator>
		<pubDate>Tue, 14 Oct 2008 11:25:46 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/13/vectorizing-the-notion-of-colon/#comment-29808</guid>
		<description>I've been trying to find out a bit more about the performance of cellfun and arrayfun.  I use these functions quite regularly to step through large cell arrays and I'm curious how they compare to doing a standard for loop (as discussed in this article.)

Does anyone have any thoughts pertaining to this?

Thanks!</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been trying to find out a bit more about the performance of cellfun and arrayfun.  I use these functions quite regularly to step through large cell arrays and I&#8217;m curious how they compare to doing a standard for loop (as discussed in this article.)</p>
<p>Does anyone have any thoughts pertaining to this?</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
