From: Mike Allis on
All,
Its probably a very simple answer, but its eluded me for hours.

I have multiple large files that cannot all be open in the workspace due to memory requirements. I have the user input which file to load from the current directory. As each file is loaded I then attempt to us operate on the variables just loaded (eg mean, sum, etc). The problem comes when instructing the function to operate.


simplified example of my current code:

runNo=input('input run number to analyse')

for n=1:8 % 8 columns of data within each file
filename=(sprintf('exptNo%d.mat', runNo));
load (filename); %loads the file relating to runNo
% perform some operations eg:
columnmean(runNo,n)=mean(filename(:,n));
% So I want to take the mean of each column for whatever runNo is selected
clear (filename)
end

As you can see the 3rd to last line isn't correct.

Help appreciated,
Cheers,
Mike
From: Matt J on
"Mike Allis" <m.allis(a)wrl.unsw.edu.au> wrote in message <hj2qil$nkg$1(a)fred.mathworks.com>...
> All,
> Its probably a very simple answer, but its eluded me for hours.
>
> I have multiple large files that cannot all be open in the workspace due to memory requirements. I have the user input which file to load from the current directory. As each file is loaded I then attempt to us operate on the variables just loaded (eg mean, sum, etc). The problem comes when instructing the function to operate.
>
>
> simplified example of my current code:
>
> runNo=input('input run number to analyse')
>
> for n=1:8 % 8 columns of data within each file
> filename=(sprintf('exptNo%d.mat', runNo));
> load (filename); %loads the file relating to runNo
> % perform some operations eg:
> columnmean(runNo,n)=mean(filename(:,n));
> % So I want to take the mean of each column for whatever runNo is selected
> clear (filename)
> end
>
> As you can see the 3rd to last line isn't correct.
==============

See from what? You haven't posted any output.

Anyway, your code suggests that exptNo?.mat contains a single variable also called called "exptNo?". Assuming this is true, your code should probably look like this


runNo=input('input run number to analyse')


thename=(sprintf('exptNo%d', runNo));
S=load(thename); %loads the file relating to runNo

columnmean(runNo)=mean(S.thename);

clear S

Notice 2 important things.

(1) No for-loop is necessary.

(2) Notice how I piped the result to a structure, S.
You should never call load() without an output argument unless you're absolutely sure that the variable names in the file won't conflict with anything.
This avoids hazards of so-called "poofing":

http://www.mathworks.com/matlabcentral/newsreader/view_thread/270275

http://www.mathworks.com/matlabcentral/newsreader/view_thread/244639