From: Peter Smith on
Appologies, i was a little confused over what i was trying to ask. Now i am sure what i need to do; again.......

> i have 310 .mat files - from these 310 files i want to
> : sequentially open up a variable - spreadMat
> : calculate an AverageDailySpread for evey day, each variable will be a 1*244 vector
> : insert the vectors into a matrix, where the dimentions are
> (length(dates), length(AveragDailySpread)) - 310*244

Hence i need to insert the 310 AverageDailySpreads;

Here is my code;

clear;

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

tmp = dir([rootDir '*.mat']);
fnames = char({tmp.name}');
clear tmp;

dates = unique(cellstr(fnames(:,1:8)));

for i=1: length(dates)

FullFnames = ['C:\Users\Alex Eptas\Desktop\ChiXDaily\' dates{i} '_chix.mat'];

load(FullFnames , 'spreadMat')

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

for j=1: length(AverageDailySpread)


if j==1; % if this is the first file opened, create a matrix to contain the AverageDailySpreadFiles - 310*244
masterID = AverageDailySpread;
SpreadMatrix = NaN(length(dates),length(masterID));
end;

idx = find(masterID==AverageDailySpread(j));
if ~isempty(idx);

SpreadMatrix(i,idx)=AverageDailySpread(j);

end;

end;

end;


However, after the code runs, the final SpreadMatrix, which is supposed to contain the 310 vectors only contains the vector for the 310th day, nothing else.
Hence it appears that the AverageDailySpread is rewritten in each loop such that only the last file is saved.

Please could someone tell me how to solve this.
Much Appreciated.