Duke-UNC Brain Imaging and Analysis Center
BIAC Forums | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password   Forgot your Password?
 All Forums
 Support Forums
 Analysis Software Support
 Matlab - out of memory error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vvs4
Junior Member

USA
40 Posts

Posted - Dec 22 2009 :  08:46:45 AM  Show Profile  Visit vvs4's Homepage  Send vvs4 an AOL message  Reply with Quote
Hello!

I need to figure out how to not run out of memory in matlab!

I wrote a script that basically cycles through three 4D images that have been masked in various ways, and writes the values for each to a matrix. It's my first matlab script ever so its pretty simple, and probably could be made better - feel free to critique! When I was testing on one image, the commands all worked and ran successfully. When I wrote it into a script, I receive the following error message:

> In Voxel_matrix_prep at 28
??? Error using ==> zeros
Out of memory. Type HELP MEMORY for your options.

Error in ==> spm_read_vols at 31
Y = zeros([V(1).dim(1:3),n]); %-image data matrix

Error in ==> Voxel_matrix_prep at 28
vox=spm_read_vols(img);


I tried running the commands again in the matlab window, and again received the error message. I can't figure out why I'm running out of memory now, but did not before when I was testing the commands. I went into the task manager and closed all unnecessary processes, and went into System --> Advanced --> Performance --> Settings --> Advanced --> Virtual Memory --> Change and changed the paging file size to 20000 to 50000 for drive C: (McKell showed me how to do this), I can't remember if this would be large enough? I still received the error message.

My system is Windows XP 32 bit 4GHz (I know, should have thought about 64 bit). I am hopeful that someone can help me fix this problem, or do I need to use a more powerful machine to run this on? If so, where can I find a computer with more memory to use?

Many thanks for your help BIAC! I will include my matlab script below.

Best,

Vanessa

%VOXEL_MATRIX_PREP
% Takes input 4D image files and creates a matrix of
% intensities. the 4D files are located under
% munin(N:/FIGS.01/Analysis/Data/SPMFaces/SPM2Processed/$SUBJECT

% including:
% faces_4D_swrf_stanmasked (standard and subject mask)
% faces_4D_swrf_submasked_noeyes.nii (just subject, eyes removed)
% faces_4D_swrf_ROI (subject, standard, then right amygdala masked)

% Output goes to Analysis/SPMFaces/Matrices

% Matlab help from Patrick Fisher, Pittsburgh
% Script by Vanessa Sochat, Duke

subjects={'040526121358', '040526133543'}

for i=1; length(subjects)

subj=subjects{i}

% Navigate to subject folder
foldertogoto=['N:/FIGS.01/Data/SPMFaces/SPM2Processed/' (subj) '/Faces'];
cd(foldertogoto);

% first do for faces_4D_swrf_stanmasked
img=spm_vol('faces_4D_swrf_stanmasked.nii');
vox=spm_read_vols(img);

% save to SPMFaces/Matrices/Standard
filetosave=['N:/FIGS.01/Data/SPMFaces/Matrices/Standard/' (subj) '_matrix'];
save(filetosave, 'vox')
clear

% now do for faces_4D_swrf_submasked_noeyes
img=spm_vol('faces_4D_swrf_submasked_noeyes.nii');
vox=spm_read_vols(img);

% save to SPMFaces/Matrices/Subject
filetosave=['N:/FIGS.01/Data/SPMFaces/Matrices/Subject/' (subj) '_matrix'];
save(filetosave, 'vox')
clear

% NOW DO FOR faces_4D_swrf_ROI
img=spm_vol('faces_4D_swrf_ROI.nii');
vox=spm_read_vols(img);

% save to SPMFaces/ROI
filetosave=['N:/FIGS.01/Data/SPMFaces/Matrices/ROI/' (subj) '_matrix'];
save(filetosave, 'vox')
clear

end


-Vanessa

syam.gadde
BIAC Staff

USA
421 Posts

Posted - Dec 22 2009 :  09:24:05 AM  Show Profile  Reply with Quote
It's hard to imagine that you really need 64-bit since you seem to be getting an error the very first time you read an image. How large are these 4D images?

One thing I noticed, and it may be just the forums getting rid of characters, but your for loop needs [] brackets and a colon to actually loop (your code will just loop through the first subject after printing out the number of subjects):

for i=[1:length(subjects)]

but that won't account for your error.
Go to Top of Page

josh.bizzell
BIAC Staff

USA
118 Posts

Posted - Dec 22 2009 :  09:33:27 AM  Show Profile  Reply with Quote
Also, if you have access to the BIAC Matlab scripts, (http://www.biac.duke.edu/forums/topic.asp?TOPIC_ID=928)you could try and use readmr to accomplish what it appears you're trying to do. This might run out of memory as well though, if the data you're loading is very large.

% first do for faces_4D_swrf_stanmasked
vox=readmr('faces_4D_swrf_stanmasked.nii');

% save to SPMFaces/Matrices/Standard
filetosave=['N:/FIGS.01/Data/SPMFaces/Matrices/Standard/' (subj) '_matrix'];
save(filetosave, 'vox.data')
clear
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
BIAC Forums © 2000-2010 Brain Imaging and Analysis Center Go To Top Of Page
This page was generated in 0.45 seconds. Snitz Forums 2000