From: Peter Smith on
I think my earlier post may have been misunderstood;

i have 310 .mat files - from these 310 files i want to
: sequentially open up a variable - spreadMat
: calculate an average of each of the numbers in spreadMat
: insert the numbers into a matrix, where the dimentions are
(length(dates), length(AveragDailySpread)) - so i will effectively insert one row for every file.
Once i have done this for the first file i want it to loop through, inserting the appropriate data into the correct rows;

I have this so far:


rootDir = 'C:\Users\Alex Eptas\Desktop\ChiXDaily\'; % where all the .mat files are stored
tmp = dir([rootDir '*.mat']);

fnames = char({tmp.name}'); % the names of the .mat files which are in the form of
20101224_chix.mat

clear tmp;

dates = unique(cellstr(fnames(:,1:8))); %creates a list of dates from the filenames

for i=1: length(dates) i.e. so for every date it will do the same thing

load('C:\Users\Alex Eptas\Desktop\ChiXDaily\20080606_chix.mat', 'spreadMat'); % here is the problem - i need someway to make it do this;

load('C:\Users\Alex Eptas\Desktop\ChiXDaily\date(i)_chix.mat', 'spreadMat');

then i will carry out the rest, i.e.

AverageDailySpread = nanmean(spreadMat(:,1:244));

please could someone help me
From: Eduardo on
"Peter Smith" <fe09ae(a)mail.wbs.ac.uk> wrote in message <i2svok$sll$1(a)fred.mathworks.com>...
> I think my earlier post may have been misunderstood;
>
> i have 310 .mat files - from these 310 files i want to
> : sequentially open up a variable - spreadMat
> : calculate an average of each of the numbers in spreadMat
> : insert the numbers into a matrix, where the dimentions are
> (length(dates), length(AveragDailySpread)) - so i will effectively insert one row for every file.
> Once i have done this for the first file i want it to loop through, inserting the appropriate data into the correct rows;
>
> I have this so far:
>
>
> rootDir = 'C:\Users\Alex Eptas\Desktop\ChiXDaily\'; % where all the .mat files are stored
> tmp = dir([rootDir '*.mat']);
>
> fnames = char({tmp.name}'); % the names of the .mat files which are in the form of
> 20101224_chix.mat
>
> clear tmp;
>
> dates = unique(cellstr(fnames(:,1:8))); %creates a list of dates from the filenames
>
> for i=1: length(dates) i.e. so for every date it will do the same thing
>
> load('C:\Users\Alex Eptas\Desktop\ChiXDaily\20080606_chix.mat', 'spreadMat'); % here is the problem - i need someway to make it do this;
>
> load('C:\Users\Alex Eptas\Desktop\ChiXDaily\date(i)_chix.mat', 'spreadMat');
>
> then i will carry out the rest, i.e.
>
> AverageDailySpread = nanmean(spreadMat(:,1:244));
>
> please could someone help me

How about:

fpath = 'C:\Users\Alex Eptas\Desktop\ChiXDaily\';

for i = 1:length(dates)
currentfile = fullfile(fpath, fnames(i));
load(currentfile,'spreadMat');
...
end
From: Peter Smith on
thanks but unfortunately that does not work
any other ideas?/
appreciate it

"Eduardo " <bob1182006(a)yahoo.com> wrote in message <i2t1f1$f4h$1(a)fred.mathworks.com>...
> "Peter Smith" <fe09ae(a)mail.wbs.ac.uk> wrote in message <i2svok$sll$1(a)fred.mathworks.com>...
> > I think my earlier post may have been misunderstood;
> >
> > i have 310 .mat files - from these 310 files i want to
> > : sequentially open up a variable - spreadMat
> > : calculate an average of each of the numbers in spreadMat
> > : insert the numbers into a matrix, where the dimentions are
> > (length(dates), length(AveragDailySpread)) - so i will effectively insert one row for every file.
> > Once i have done this for the first file i want it to loop through, inserting the appropriate data into the correct rows;
> >
> > I have this so far:
> >
> >
> > rootDir = 'C:\Users\Alex Eptas\Desktop\ChiXDaily\'; % where all the .mat files are stored
> > tmp = dir([rootDir '*.mat']);
> >
> > fnames = char({tmp.name}'); % the names of the .mat files which are in the form of
> > 20101224_chix.mat
> >
> > clear tmp;
> >
> > dates = unique(cellstr(fnames(:,1:8))); %creates a list of dates from the filenames
> >
> > for i=1: length(dates) i.e. so for every date it will do the same thing
> >
> > load('C:\Users\Alex Eptas\Desktop\ChiXDaily\20080606_chix.mat', 'spreadMat'); % here is the problem - i need someway to make it do this;
> >
> > load('C:\Users\Alex Eptas\Desktop\ChiXDaily\date(i)_chix.mat', 'spreadMat');
> >
> > then i will carry out the rest, i.e.
> >
> > AverageDailySpread = nanmean(spreadMat(:,1:244));
> >
> > please could someone help me
>
> How about:
>
> fpath = 'C:\Users\Alex Eptas\Desktop\ChiXDaily\';
>
> for i = 1:length(dates)
> currentfile = fullfile(fpath, fnames(i));
> load(currentfile,'spreadMat');
> ...
> end