<?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: Essence of Indexing</title>
	<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/</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>Sun, 08 Nov 2009 05:42:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-23719</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sat, 22 Dec 2007 21:38:53 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-23719</guid>
		<description>Antonio-

A singleton dimension contains only 1 index in that dimension, e.g., A(3:5,17,2:3) has the 2nd dimension as a singleton since the size of this array would be 3x1x2.

--Loren</description>
		<content:encoded><![CDATA[<p>Antonio-</p>
<p>A singleton dimension contains only 1 index in that dimension, e.g., A(3:5,17,2:3) has the 2nd dimension as a singleton since the size of this array would be 3&#215;1x2.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Siciliano Antonio</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-23705</link>
		<dc:creator>Siciliano Antonio</dc:creator>
		<pubDate>Sat, 22 Dec 2007 15:11:04 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-23705</guid>
		<description>Can you give me a clear definition of the term "singleton" and simple example relating this term?
Thanks
Antonio Siciliano</description>
		<content:encoded><![CDATA[<p>Can you give me a clear definition of the term &#8220;singleton&#8221; and simple example relating this term?<br />
Thanks<br />
Antonio Siciliano</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-17117</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 10 Sep 2007 11:19:22 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-17117</guid>
		<description>Pieter-

MATLAB doesn't currently support the syntax you'd like to use.    You must do the variable assignment and then index into the result. 

--Loren</description>
		<content:encoded><![CDATA[<p>Pieter-</p>
<p>MATLAB doesn&#8217;t currently support the syntax you&#8217;d like to use.    You must do the variable assignment and then index into the result. </p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pieter Laurens Baljon</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-17110</link>
		<dc:creator>Pieter Laurens Baljon</dc:creator>
		<pubDate>Mon, 10 Sep 2007 08:47:18 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-17110</guid>
		<description>Is there a way to immediately address the result of a method as in:
A = [21 23 24 25 26];
B = A( randperm(end)(1:3) );

The part of code I can't get working is 'randperm(end)(1:3)'. I want the first three random elements from matrix A. I could get the same result with the code:
A = [21 23 24 25 26];
idx = randperm(length(A));
B = A( idx(1:3) );
but I would prefer not to use the additional variable 'idx'.

Thanks in advance,
Pieter Laurens</description>
		<content:encoded><![CDATA[<p>Is there a way to immediately address the result of a method as in:<br />
A = [21 23 24 25 26];<br />
B = A( randperm(end)(1:3) );</p>
<p>The part of code I can&#8217;t get working is &#8216;randperm(end)(1:3)&#8217;. I want the first three random elements from matrix A. I could get the same result with the code:<br />
A = [21 23 24 25 26];<br />
idx = randperm(length(A));<br />
B = A( idx(1:3) );<br />
but I would prefer not to use the additional variable &#8216;idx&#8217;.</p>
<p>Thanks in advance,<br />
Pieter Laurens</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: I Patterson</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-16335</link>
		<dc:creator>I Patterson</dc:creator>
		<pubDate>Thu, 02 Aug 2007 06:25:15 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-16335</guid>
		<description>Hello, Definitely helpful to have all the indexing info tegether. I taught Matlab at the graduate level and once beyond the basics I then assemnled indexing tecniques into notes, explained some less obvious tecniques. I then distributed the notes and an assignment requiring the use of indexing. Seemed to work</description>
		<content:encoded><![CDATA[<p>Hello, Definitely helpful to have all the indexing info tegether. I taught Matlab at the graduate level and once beyond the basics I then assemnled indexing tecniques into notes, explained some less obvious tecniques. I then distributed the notes and an assignment requiring the use of indexing. Seemed to work</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-15968</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 07 Dec 2006 02:57:57 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-15968</guid>
		<description>Erik-

Glad you were able to get your code working.  Perhaps it would be worth posting the new version here for people to compare.

I fixed your code by reinserting the &gt; and &lt;.  However, it doesn't look identical to the code you posted to the newsgroup (an if-end chunk missing).  FYI, the software doesn't remove &gt;,&lt; if they are inside the html pre tags.

--Loren</description>
		<content:encoded><![CDATA[<p>Erik-</p>
<p>Glad you were able to get your code working.  Perhaps it would be worth posting the new version here for people to compare.</p>
<p>I fixed your code by reinserting the > and < .  However, it doesn't look identical to the code you posted to the newsgroup (an if-end chunk missing).  FYI, the software doesn't remove >,< if they are inside the html pre tags.</p>
</p><p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: erik</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-15964</link>
		<dc:creator>erik</dc:creator>
		<pubDate>Wed, 06 Dec 2006 23:04:41 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-15964</guid>
		<description>http://blogs.mathworks.com/loren/?p=28
and
http://blogs.mathworks.com/loren/?p=65#12
were just what i needed, thanks!  i knew i was being dumb.

incidentally, the code i posted worked fine, i just thought it was ugly and knew you would know of a better way.  it does have comments that describe its specification and i think they are pretty simple, plus i posted a reference to the matlab documentation that explains the algorithm.  i did not know that pre tags were necessary to prevent the blog software from mangling code (i guess less than and greater than signs are dangerous on the web) -- i merely pasted in text from my m-file editor.  anyway, the code pasted fine into that matlab forum at:
http://newsreader.mathworks.com/WebX?14@896.8e9dbxh5WSs@.ef47e04

it looks like this blog software removes anything between a less than or equal sign and the next greater than sign (even if that is several lines later) from your readers' posts.  just fyi.

thanks again,
-erik</description>
		<content:encoded><![CDATA[<p><a href="http://blogs.mathworks.com/loren/?p=28" rel="nofollow">http://blogs.mathworks.com/loren/?p=28</a><br />
and<br />
<a href="http://blogs.mathworks.com/loren/?p=65#12" rel="nofollow">http://blogs.mathworks.com/loren/?p=65#12</a><br />
were just what i needed, thanks!  i knew i was being dumb.</p>
<p>incidentally, the code i posted worked fine, i just thought it was ugly and knew you would know of a better way.  it does have comments that describe its specification and i think they are pretty simple, plus i posted a reference to the matlab documentation that explains the algorithm.  i did not know that pre tags were necessary to prevent the blog software from mangling code (i guess less than and greater than signs are dangerous on the web) &#8212; i merely pasted in text from my m-file editor.  anyway, the code pasted fine into that matlab forum at:<br />
<a href="http://newsreader.mathworks.com/WebX?14@896.8e9dbxh5WSs@.ef47e04" rel="nofollow">http://newsreader.mathworks.com/WebX?14@896.8e9dbxh5WSs@.ef47e04</a></p>
<p>it looks like this blog software removes anything between a less than or equal sign and the next greater than sign (even if that is several lines later) from your readers&#8217; posts.  just fyi.</p>
<p>thanks again,<br />
-erik</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-15956</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 06 Dec 2006 16:13:18 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-15956</guid>
		<description>Erik-

Your code has no comments or examples.  I plan to pass on reading it to try to understand it.  I put some html markers surrounding the code ( &lt; pre &gt; and &lt; /pre &gt;  but without the spaces) to make the code you placed there more readable in case someone else wants to tackle it.  Plus it appears to be invalid code the way you typed it in, e.g., &lt;kbd&gt;any(inds(:)maxes(:))&lt;/kbd&gt; and some mlint warnings that could get cleaned up to help a reader and the code.  Finally, you are allowed to index into an array with more indices than the value returned by &lt;kbd&gt;ndims&lt;/kbd&gt; provided all the extra indices are 1.

You may also benefit from reading one of the more recent posts on using the : operator, though I don't know if it is actually applicable here: http://blogs.mathworks.com/loren/?p=65

--Loren</description>
		<content:encoded><![CDATA[<p>Erik-</p>
<p>Your code has no comments or examples.  I plan to pass on reading it to try to understand it.  I put some html markers surrounding the code ( < pre > and < /pre >  but without the spaces) to make the code you placed there more readable in case someone else wants to tackle it.  Plus it appears to be invalid code the way you typed it in, e.g., <kbd>any(inds(:)maxes(:))</kbd> and some mlint warnings that could get cleaned up to help a reader and the code.  Finally, you are allowed to index into an array with more indices than the value returned by <kbd>ndims</kbd> provided all the extra indices are 1.</p>
<p>You may also benefit from reading one of the more recent posts on using the : operator, though I don&#8217;t know if it is actually applicable here: <a href="http://blogs.mathworks.com/loren/?p=65" rel="nofollow">http://blogs.mathworks.com/loren/?p=65</a></p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: erik</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-15955</link>
		<dc:creator>erik</dc:creator>
		<pubDate>Wed, 06 Dec 2006 16:08:06 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-15955</guid>
		<description>hi loren.  am i being dumb, or is there a way to do the following built into matlab?  i frequently need to look up entries in n-d data and can't know ahead of time what n is.  thus, the normal indexing using comma separated lists won't work unless i can generate comma separated lists dynamically and have matlab recognize each item as a separate argument.  i wrote the following function based on the information at
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f1-86846.html
but it seems like a clunky hack for something that could very naturally be a part of the language.  an alternative to the strategy i used would be to generate the appropriate sparse n-d logical index, but i couldn't think of a clean way to do that -- could you address how to do that as well?
-e

&lt;pre&gt;
function out=lookup(a,inds)
%a is an n-d array
%inds is an m x n matrix
%out is an 1 x m vector containing the entries in a 
%specified by the coordinates in each row of inds

if length(size(a))==2 &#38;&#38; any(size(a)==1)
    out=a(inds);
else
    maxes=repmat(size(a),size(inds,1),1);
    if size(inds,2)~=length(size(a))
        error('wrong num cols in inds')
    end
    if any(inds(:)&gt;maxes(:))
        ers=find(inds&gt;maxes)
        inds(ers)
        maxes(1,:)
        size(a)
        error('got inds &gt; size(a)')
    end

    factors=ones(size(inds,1),1);
    offsets=zeros(size(inds,1),1);
    sz=size(a);
    for i=1:length(sz)-1
        factors(:,i+1)=prod(sz(1:i));
        offsets(:,i+1)=-1;
    end
    out=a(sum([(inds+offsets).*factors]'));
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>hi loren.  am i being dumb, or is there a way to do the following built into matlab?  i frequently need to look up entries in n-d data and can&#8217;t know ahead of time what n is.  thus, the normal indexing using comma separated lists won&#8217;t work unless i can generate comma separated lists dynamically and have matlab recognize each item as a separate argument.  i wrote the following function based on the information at<br />
<a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f1-86846.html" rel="nofollow">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f1-86846.html</a><br />
but it seems like a clunky hack for something that could very naturally be a part of the language.  an alternative to the strategy i used would be to generate the appropriate sparse n-d logical index, but i couldn&#8217;t think of a clean way to do that &#8212; could you address how to do that as well?<br />
-e</p>
<pre>
function out=lookup(a,inds)
%a is an n-d array
%inds is an m x n matrix
%out is an 1 x m vector containing the entries in a
%specified by the coordinates in each row of inds

if length(size(a))==2 &amp;&amp; any(size(a)==1)
    out=a(inds);
else
    maxes=repmat(size(a),size(inds,1),1);
    if size(inds,2)~=length(size(a))
        error('wrong num cols in inds')
    end
    if any(inds(:)>maxes(:))
        ers=find(inds>maxes)
        inds(ers)
        maxes(1,:)
        size(a)
        error('got inds > size(a)')
    end

    factors=ones(size(inds,1),1);
    offsets=zeros(size(inds,1),1);
    sz=size(a);
    for i=1:length(sz)-1
        factors(:,i+1)=prod(sz(1:i));
        offsets(:,i+1)=-1;
    end
    out=a(sum([(inds+offsets).*factors]'));
end
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-14014</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 30 Oct 2006 12:00:37 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/#comment-14014</guid>
		<description>Paolo-

I recommend you look at the comments by Erik and me in &lt;a href="http://blogs.mathworks.com/loren/?p=39" rel="nofollow"&gt;this blog article&lt;/a&gt;.  You'll see examples where cellfun and arrayfun can do what you need.

--Loren</description>
		<content:encoded><![CDATA[<p>Paolo-</p>
<p>I recommend you look at the comments by Erik and me in <a href="http://blogs.mathworks.com/loren/?p=39" rel="nofollow">this blog article</a>.  You&#8217;ll see examples where cellfun and arrayfun can do what you need.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>
