<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255234</link>
    <title>MATLAB Central Newsreader - Accessing random sections of 3D matrices- why does execution time vary widely?</title>
    <description>Feed for thread: Accessing random sections of 3D matrices- why does execution time vary widely?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 03 Jul 2009 01:49:01 -0400</pubDate>
      <title>Accessing random sections of 3D matrices- why does execution time vary widely?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255234#662413</link>
      <author>Susan Wardle</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I've been stuck on this problem for a while, and I haven't found the solution in the documentation, so I thought I'd try the experts...&lt;br&gt;
&lt;br&gt;
The problem is that 2 parts of my code have widely variable execution times, and I cannot see the reason for this.&lt;br&gt;
(I need the shortest execution time possible because I am creating movies to show participants in a Psychology experiment- the matrix contains the pixel values to draw patterns on the screen)&lt;br&gt;
---------------------------------------------------------------------------------------------&lt;br&gt;
1. I am using large double precision (300 x 300 x 300) 3D matrices, and I want to access random segments of 100 consecutive slices in the third dimension eg: (:,:,1:100). &lt;br&gt;
&lt;br&gt;
Looping the line of code copied below 20 times produced a range of durations from 0.3-3.7 seconds. &lt;br&gt;
&lt;br&gt;
Fmovie=FmovieWhole(:,:,ranf(n):ranf(n)+99); &lt;br&gt;
&lt;br&gt;
FmovieWhole is the parent (300 x 300 x 300) matrix, randf is an array of random integers used to pick the starting index for the random slice, and Fmovie is the (300 x 300 x 100) slice (and it is preallocated initially for speed).&lt;br&gt;
---------------------------------------------------------------------------------------------&lt;br&gt;
2. This section of code varied from taking 1.3 - 4.7 seconds to execute when I ran it 20 times.&lt;br&gt;
Vmovie is a 300 x 300 x 100 matrix and the code below changes the pixel values to adjust the contrast of the image. VLinContrast is a scaler.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vmovie=Vmovie./255; %normalise 0-1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rms=std2(Vmovie); %rms contrast&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;meanLum=mean2(Vmovie);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vmovie=Vmovie-meanLum;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vmovie=Vmovie.*(VLinContrast/rms) +meanLum;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vmovie=Vmovie.*255;&lt;br&gt;
&lt;br&gt;
Perhaps these problems are related to how memory has been allocated?&lt;br&gt;
&lt;br&gt;
My computer is a 1.8 GHz PowerPC Mac with 1GB RAM running Matlab R2007a &lt;br&gt;
&lt;br&gt;
Any suggestions or detail about how Matlab stores 3D matrices in memory would be greatly appreciated!&lt;br&gt;
&lt;br&gt;
thanks,&lt;br&gt;
&lt;br&gt;
Susan</description>
    </item>
  </channel>
</rss>

