Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Accessing random sections of 3D matrices- why does execution time vary widely?
Date: Fri, 3 Jul 2009 01:49:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 34
Message-ID: <h2jo2d$d7m$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246585741 13558 172.30.248.38 (3 Jul 2009 01:49:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 3 Jul 2009 01:49:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1895272
Xref: news.mathworks.com comp.soft-sys.matlab:552588


Hi,

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...

The problem is that 2 parts of my code have widely variable execution times, and I cannot see the reason for this.
(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)
---------------------------------------------------------------------------------------------
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). 

Looping the line of code copied below 20 times produced a range of durations from 0.3-3.7 seconds. 

Fmovie=FmovieWhole(:,:,ranf(n):ranf(n)+99); 

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).
---------------------------------------------------------------------------------------------
2. This section of code varied from taking 1.3 - 4.7 seconds to execute when I ran it 20 times.
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.

    Vmovie=Vmovie./255; %normalise 0-1
    rms=std2(Vmovie); %rms contrast
    meanLum=mean2(Vmovie);
    Vmovie=Vmovie-meanLum;
    Vmovie=Vmovie.*(VLinContrast/rms) +meanLum;
    Vmovie=Vmovie.*255;

Perhaps these problems are related to how memory has been allocated?

My computer is a 1.8 GHz PowerPC Mac with 1GB RAM running Matlab R2007a 

Any suggestions or detail about how Matlab stores 3D matrices in memory would be greatly appreciated!

thanks,

Susan