<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Indexing Terminology</title>
	<atom:link href="http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 09 Feb 2012 04:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Kishore</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-30569</link>
		<dc:creator>Kishore</dc:creator>
		<pubDate>Thu, 03 Sep 2009 21:36:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-30569</guid>
		<description>Thanks!! Loren.

~kishore</description>
		<content:encoded><![CDATA[<p>Thanks!! Loren.</p>
<p>~kishore</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-30562</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 02 Sep 2009 10:54:04 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-30562</guid>
		<description>Kishore-

We highly recommend that you do not create variables named sequentially like you might in C.  Please look at &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F&quot; rel=&quot;nofollow&quot;&gt; this article&lt;/a&gt; in the MATLAB FAQ.

--Loren</description>
		<content:encoded><![CDATA[<p>Kishore-</p>
<p>We highly recommend that you do not create variables named sequentially like you might in C.  Please look at <a href="http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F" rel="nofollow"> this article</a> in the MATLAB FAQ.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kishore</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-30560</link>
		<dc:creator>Kishore</dc:creator>
		<pubDate>Wed, 02 Sep 2009 00:34:49 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-30560</guid>
		<description>Hi Loren!,

I have a problem.SO,was going through this post. I still dont have an answer so i post it here.

I have a 2 dimensional matrix which i read from a file.There are multiple files, sigma1, sigma2 and so on,
I read it from the file and assign it to a local variable ( a 3 dimensional matrix) and reassign this another variable, which i intend to use in the actual code. But i have difficulties in indexing. I am sort of confused.

My question, can i use something similar to ## in C to append a number to a variable, for example

&lt;pre&gt;

MU##1 = MU;  %assign matrix MU to MU1;

&lt;/pre&gt;


My code is here anyways


&lt;pre&gt;


for i =1:N  % for each state of nature wi
   for j = 1:M,
         mu = strcat(&#039;K:\MU&#039;,int2str(i),&#039;.txt&#039;);
         sig = strcat(&#039;K:\SIGMA&#039;,int2str(i),&#039;.txt&#039;); 
    data_mu = load(mu);
    data_sig = load(sig);
     MU(i,:,j) = data_mu(:,j); % load different columns to 3d ARRAY
     SIGMA(i,:,j) = data_sig(:,j);
   end
end

MU1 = MU(1,:,:); % load matrix of first dimension.
SIGMA1 = SIGMA(1,:,:);




&lt;/pre&gt;

Ex : sigma = [2 0;0 0.5];



Thanks !</description>
		<content:encoded><![CDATA[<p>Hi Loren!,</p>
<p>I have a problem.SO,was going through this post. I still dont have an answer so i post it here.</p>
<p>I have a 2 dimensional matrix which i read from a file.There are multiple files, sigma1, sigma2 and so on,<br />
I read it from the file and assign it to a local variable ( a 3 dimensional matrix) and reassign this another variable, which i intend to use in the actual code. But i have difficulties in indexing. I am sort of confused.</p>
<p>My question, can i use something similar to ## in C to append a number to a variable, for example</p>
<pre>

MU##1 = MU;  %assign matrix MU to MU1;
</pre>
<p>My code is here anyways</p>
<pre>

for i =1:N  % for each state of nature wi
   for j = 1:M,
         mu = strcat('K:\MU',int2str(i),'.txt');
         sig = strcat('K:\SIGMA',int2str(i),'.txt');
    data_mu = load(mu);
    data_sig = load(sig);
     MU(i,:,j) = data_mu(:,j); % load different columns to 3d ARRAY
     SIGMA(i,:,j) = data_sig(:,j);
   end
end

MU1 = MU(1,:,:); % load matrix of first dimension.
SIGMA1 = SIGMA(1,:,:);
</pre>
<p>Ex : sigma = [2 0;0 0.5];</p>
<p>Thanks !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-30322</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Fri, 15 May 2009 14:13:33 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-30322</guid>
		<description>Glad to find this discussion: whilst meshgrid and its family are excellent starting points for regridding (2D) &quot;images&quot;, when volumes or time varying volumes appear, then ndgrid must be used. OK, so far, but then we find that stream3, streamtube etc require meshgrid. Meshgrid for 3D data (e.g. look at &quot;wind&quot; in the examples)? Why oh why oh why?

So, here&#039;s the solution I request. 

If GIVEN some volume data (e.g., &quot;wind&quot;) which has meshgrid orientation, give me

mesh2nd(x,y,z,u,v,w) 

which flips round (or regrids) the x,y and z, and ALSO suitably transposes the u,v,w, so it matches the transformed x,y &amp; z. 

Either today is a fuzzy Friday for me, or this is not a simple as it may sound.

Cheers,</description>
		<content:encoded><![CDATA[<p>Glad to find this discussion: whilst meshgrid and its family are excellent starting points for regridding (2D) &#8220;images&#8221;, when volumes or time varying volumes appear, then ndgrid must be used. OK, so far, but then we find that stream3, streamtube etc require meshgrid. Meshgrid for 3D data (e.g. look at &#8220;wind&#8221; in the examples)? Why oh why oh why?</p>
<p>So, here&#8217;s the solution I request. </p>
<p>If GIVEN some volume data (e.g., &#8220;wind&#8221;) which has meshgrid orientation, give me</p>
<p>mesh2nd(x,y,z,u,v,w) </p>
<p>which flips round (or regrids) the x,y and z, and ALSO suitably transposes the u,v,w, so it matches the transformed x,y &amp; z. </p>
<p>Either today is a fuzzy Friday for me, or this is not a simple as it may sound.</p>
<p>Cheers,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-18377</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 27 Sep 2007 13:25:08 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-18377</guid>
		<description>Guys-

You might try this code (using the opengl renderer, which MATLAB will do automatically with the transparency - though there are bugs in various opengl drivers and they don&#039;t all look the same). 

&lt;pre class=&quot;code&quot;&gt;
A = magic(3)
AA  = A
AA(1) = NaN
imalpha = ones(size(A));
h = image(AA), colorbar
colormap(jet(9))
imalpha(isnan(AA)) = 0
set(h,&#039;alphadata&#039;,imalpha)

&lt;/pre&gt;

If your picture doesn&#039;t look right, close your figure and use this command first:

opengl software

and then retry.  The graphics will be a bit slower but will tend to overcome hardware opengl issues typically.

--Loren</description>
		<content:encoded><![CDATA[<p>Guys-</p>
<p>You might try this code (using the opengl renderer, which MATLAB will do automatically with the transparency &#8211; though there are bugs in various opengl drivers and they don&#8217;t all look the same). </p>
<pre class="code">
A = magic(3)
AA  = A
AA(1) = NaN
imalpha = ones(size(A));
h = image(AA), colorbar
colormap(jet(9))
imalpha(isnan(AA)) = 0
set(h,'alphadata',imalpha)
</pre>
<p>If your picture doesn&#8217;t look right, close your figure and use this command first:</p>
<p>opengl software</p>
<p>and then retry.  The graphics will be a bit slower but will tend to overcome hardware opengl issues typically.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xingong Li</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-18324</link>
		<dc:creator>Xingong Li</dc:creator>
		<pubDate>Thu, 27 Sep 2007 03:03:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-18324</guid>
		<description>I have exactly the same problem as Roy Goodman has. I&#039;m surprised that Roy&#039;s email was posted only recently (I started using Matlab a year ago). Most of the matrix data I want to display have some NaN elements in them. Is it possible to add another &#039;property&#039; and &#039;value&#039; pair to specify the color for displaying the NaN elements in a matrix?

Thanks,
Xingong</description>
		<content:encoded><![CDATA[<p>I have exactly the same problem as Roy Goodman has. I&#8217;m surprised that Roy&#8217;s email was posted only recently (I started using Matlab a year ago). Most of the matrix data I want to display have some NaN elements in them. Is it possible to add another &#8216;property&#8217; and &#8216;value&#8217; pair to specify the color for displaying the NaN elements in a matrix?</p>
<p>Thanks,<br />
Xingong</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roy Goodman</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-17126</link>
		<dc:creator>Roy Goodman</dc:creator>
		<pubDate>Mon, 10 Sep 2007 16:07:12 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-17126</guid>
		<description>I was most interested in the use of the commands image and imagesc to plot the values of items in matrices.  

I had been using pcolor along with &#039;shading flat&#039; to achieve almost the same effect.  The problem with doing this is that in plotting the contents of an n x n array, you get a figure with an (n-1)x(n-1) array of elements, the last row and column being ignored.  

I would like to use image instead of pcolor for my applications (using &#039;axis xy&#039; to preserve orientation), but for one small hitch.  pcolor treats  NaN&#039;s as blanks whereas image and imagesc treat them as zeros.  I need them to be treated as blanks, so I keep using pcolor.  A further problem with using pcolor is that I don&#039;t find the ticklabels line up nicely with the centers of the colorblocks as they do in the magic square example above. Loren, please help. is there anything I can do?

I realize that one workaround is to add an extra row and column to my array of data, but this seems like an ugly hack.  

More details: all the data in my matrix is positive integers, so another workaround is for me to convert all the NaN&#039;s to zeros before using &#039;image&#039;.  The problem now becomes that the zeros (which I want to ignore) show up in the colorbar.

Thanks,
Roy</description>
		<content:encoded><![CDATA[<p>I was most interested in the use of the commands image and imagesc to plot the values of items in matrices.  </p>
<p>I had been using pcolor along with &#8216;shading flat&#8217; to achieve almost the same effect.  The problem with doing this is that in plotting the contents of an n x n array, you get a figure with an (n-1)x(n-1) array of elements, the last row and column being ignored.  </p>
<p>I would like to use image instead of pcolor for my applications (using &#8216;axis xy&#8217; to preserve orientation), but for one small hitch.  pcolor treats  NaN&#8217;s as blanks whereas image and imagesc treat them as zeros.  I need them to be treated as blanks, so I keep using pcolor.  A further problem with using pcolor is that I don&#8217;t find the ticklabels line up nicely with the centers of the colorblocks as they do in the magic square example above. Loren, please help. is there anything I can do?</p>
<p>I realize that one workaround is to add an extra row and column to my array of data, but this seems like an ugly hack.  </p>
<p>More details: all the data in my matrix is positive integers, so another workaround is for me to convert all the NaN&#8217;s to zeros before using &#8216;image&#8217;.  The problem now becomes that the zeros (which I want to ignore) show up in the colorbar.</p>
<p>Thanks,<br />
Roy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver A. Chapman, P.E.</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-16302</link>
		<dc:creator>Oliver A. Chapman, P.E.</dc:creator>
		<pubDate>Thu, 28 Jun 2007 21:07:15 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-16302</guid>
		<description>Loren,

I read and re-read this column several times over the past few days and I&#039;m still confused.  I regularly use indexing in MatLab and find that it very powerful tool in writing compact, easy to understand code.

But this xy option is very confusing to me.  I had never previously noticed the xy option in the axis function and based on this column, I took some time to try to understand the value or benefit of that option.  I also tried to follow your example regarding ndgrid and found myself bumping up against one of the few serious limitations within MatLab.  That is MatLab&#039;s poor capability regarding table lookups.  In the past when I&#039;ve tried to figure out how to use interpn, I&#039;ve been tripped up by the example in the function reference page that uses ndgrid.  There is something fundamental about the ndgrid function that I&#039;m not getting and I wonder if it is related to this ij vs xy concept.

I&#039;m with Jessee above, pick a standard and stick with it.  Just because MatLab can provide alternate ways to do things doesn&#039;t mean that there is a benefit to the alternate way.  My experience is that the indexing method is widely used in MatLab so that should be the standard.

Maybe you need to write a detailed column that goes beyond the single example in the function reference page for ndgrid and also provides a proper description of the ndgrid function.  e.g., the description says that it transforms the domain specified by the vectors into arrays.  But, it doesn&#039;t say how they are transformed.

Anyway, after all this, I still don&#039;t understand what the significance is for this xy indexing.</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>I read and re-read this column several times over the past few days and I&#8217;m still confused.  I regularly use indexing in MatLab and find that it very powerful tool in writing compact, easy to understand code.</p>
<p>But this xy option is very confusing to me.  I had never previously noticed the xy option in the axis function and based on this column, I took some time to try to understand the value or benefit of that option.  I also tried to follow your example regarding ndgrid and found myself bumping up against one of the few serious limitations within MatLab.  That is MatLab&#8217;s poor capability regarding table lookups.  In the past when I&#8217;ve tried to figure out how to use interpn, I&#8217;ve been tripped up by the example in the function reference page that uses ndgrid.  There is something fundamental about the ndgrid function that I&#8217;m not getting and I wonder if it is related to this ij vs xy concept.</p>
<p>I&#8217;m with Jessee above, pick a standard and stick with it.  Just because MatLab can provide alternate ways to do things doesn&#8217;t mean that there is a benefit to the alternate way.  My experience is that the indexing method is widely used in MatLab so that should be the standard.</p>
<p>Maybe you need to write a detailed column that goes beyond the single example in the function reference page for ndgrid and also provides a proper description of the ndgrid function.  e.g., the description says that it transforms the domain specified by the vectors into arrays.  But, it doesn&#8217;t say how they are transformed.</p>
<p>Anyway, after all this, I still don&#8217;t understand what the significance is for this xy indexing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathias</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-16295</link>
		<dc:creator>Mathias</dc:creator>
		<pubDate>Fri, 22 Jun 2007 09:39:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-16295</guid>
		<description>I personally usually think of &quot;meshgrid&quot; as the worst Matlab function - note that I do enjoy most of them. 

I have my own  imho-owell-oriented meshgrid function, with a different name, but some functions such as interp2 (TBC) require the grid to be meshgrid-generated ! 

This change of convention is a nightmare. As an image processing engineer, I find it so easier to keep the same convention : x goes with row index, hence row index is a natural discretization of x direction, while y goes with column index.  

Obviously the obtained Cartesian grid is not in the usual direction (north to south for X and west to east for Y), but it makes a lot of computation so easier  - especially when going from continuous to discrete representations, which is when hard things usually begin (think of a warping between two images, for instance).  

I think it is easier to rotate the Cartesian coordinate system, in order to have a consistent (i,j) and (x,y) notation. It keeps both the axes direct (angles in the right directions) and the matrix multiplication (IDL convention is a nightmare).


Anyhow, this is my Humble Opinion - Keep the good work  !!
(hi Loren, I am one of the Toulouse guy: it was nice meeting you !!)

Mathias</description>
		<content:encoded><![CDATA[<p>I personally usually think of &#8220;meshgrid&#8221; as the worst Matlab function &#8211; note that I do enjoy most of them. </p>
<p>I have my own  imho-owell-oriented meshgrid function, with a different name, but some functions such as interp2 (TBC) require the grid to be meshgrid-generated ! </p>
<p>This change of convention is a nightmare. As an image processing engineer, I find it so easier to keep the same convention : x goes with row index, hence row index is a natural discretization of x direction, while y goes with column index.  </p>
<p>Obviously the obtained Cartesian grid is not in the usual direction (north to south for X and west to east for Y), but it makes a lot of computation so easier  &#8211; especially when going from continuous to discrete representations, which is when hard things usually begin (think of a warping between two images, for instance).  </p>
<p>I think it is easier to rotate the Cartesian coordinate system, in order to have a consistent (i,j) and (x,y) notation. It keeps both the axes direct (angles in the right directions) and the matrix multiplication (IDL convention is a nightmare).</p>
<p>Anyhow, this is my Humble Opinion &#8211; Keep the good work  !!<br />
(hi Loren, I am one of the Toulouse guy: it was nice meeting you !!)</p>
<p>Mathias</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-16294</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 21 Jun 2007 19:37:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/#comment-16294</guid>
		<description>Jessee-

Which convention to choose?  And why that one?  Both are natural in different situations.  Hence the dilemma.

--Loren</description>
		<content:encoded><![CDATA[<p>Jessee-</p>
<p>Which convention to choose?  And why that one?  Both are natural in different situations.  Hence the dilemma.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>

