Problem in appending matrices in vertical form
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi everybody!
I have 205 .mat files of size 31590x4 and I have a script that takes the averages every 15 minutes so that every file is reduced to a size 34x4. So my main goal after calculating the 15 min intervals is to put all these reduced files into a single .mat file that I can use later for other calculations.
The following script does the interval calculations withough problems, but when it is time to concatenate every reduced file, it turns out a new file of size double. This is wrong because the size of my new big file should be size 6970x4.
All_Data=[];
dataFiles=dir('*.mat');
for d=1:length(dataFiles)
file=dataFiles(d).name;
fileData=load(file);
finalData=fileData(d).finalData;
%fileName=dataFiles(d).name;
%fopen(fileName);
%NAME DATE, STOCK AND TIMESTAMP
date=finalData(2:end,2);
%date = fileData(2:end,1);
timestamp = finalData(2:end,2);
stockname = finalData(2:end,3);
%NAME BID VARIABLES
bid1 = cell2mat(finalData(2:end,4));
%NAME ASK VARIABLES
ask1 = cell2mat(finalData(2:end,14));
%NAME BID VOLUMES
bvol1=cell2mat(finalData(2:end,24));
%NAME ASK VOLUMES
avol1 = cell2mat(finalData(2:end,34));
%CONVERT TIMESTAMP AND DATE INTO NUMERIC VALUE
dateNumeric = datenum([date{:}],'dd.mm.yy');
timeNumeric = datenum([timestamp{:}],'HH:MM:SS');
%CALCULATE TIME INTERVALS
t = dateNumeric+timeNumeric;
t15 = datenum('00:15:00','HH:MM:SS')-datenum('00:00:00','HH:MM:SS');
ngroups = ceil((max(t)-min(t))/t15); %number of bins
findfirsttime =find(timeNumeric,1,'first');
firsttimestamp=timeNumeric(findfirsttime);
differences=zeros(size(t)); %assign memory
differences = timeNumeric(:)-firsttimestamp(:);
binNumbers=differences*96;
FifteenMinBins=floor(binNumbers);
%CALCULATE BID MEANS
b1=accumarray(1+FifteenMinBins(:),bid1(:),[],@mean);
%CALCULATE ASK MEANS
a1=accumarray(1+FifteenMinBins(:),ask1(:),[],@mean);
%CALCULATE BID VOLUMES
bv1=accumarray(1+FifteenMinBins(:),bvol1(:),[],@mean);
%CALCULATE ASK VOLUMES
av1=accumarray(1+FifteenMinBins(:),avol1(:),[],@mean);
%CALCULATE TIME INTERVALS FOR TIME
timeinterval=accumarray(1+FifteenMinBins(:),timeNumeric(:),[],@mean);
%GET FIRST 34 NUMERIC VALUES OF DATE
getdatenumber=dateNumeric(1:34);
%COLLECT OUTPUT IN MATRIX
Output_Matrix=[getdatenumber timeinterval b1 a1 bv1 av1];
%for j=1:length(dataFiles)
All_Data=[All_Data;Output_Matrix];
%end
%fclose(fid);
end
Do you see somthing wrong in my code? I´m learning matlab so I´m trying to do the best I can . Thank you so much for your help!
Have a nice day!
Lourdes
Hi ! I edit my first post since I took your suggestions into account, but now when I try to put everything in a matrix it tells me that : ??? Index exceeds matrix dimensions.
I do n´t know why, do you have any other suggestions that could help me put all these variables into a single .mat file?
THank you soo much :)
0 comentarios
Respuestas (2)
Walter Roberson
el 16 de Mayo de 2011
I haven't looked closely, but one thing I notice is that your Volume calculation is exactly the same as your mean calculation. I suspect for the Volume calculations you want @sum instead of @mean
Oleg Komarov
el 16 de Mayo de 2011
- no trace of finalData declaration (where does it come from)
- you don't need the inner loop. Keep just the command inside.
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!