Problem in appending matrices in vertical form

2 ビュー (過去 30 日間)
Lu
Lu 2011 年 5 月 16 日
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 :)

回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 5 月 16 日
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
  1 件のコメント
Lu
Lu 2011 年 5 月 17 日
Dear Walter,
Thank you for pointing this out! I changed it already! :) Do you have any other ideas of why is the script is not appending?
Thank you so much!

サインインしてコメントする。


Oleg Komarov
Oleg Komarov 2011 年 5 月 16 日
  • no trace of finalData declaration (where does it come from)
  • you don't need the inner loop. Keep just the command inside.
  1 件のコメント
Lu
Lu 2011 年 5 月 17 日
Dear Oleg,
Thank you for the reply! When I load any of the .mat files, they load into my workspace as finalData of size 31590x4. I will try taking out the inner loop, but Is there another way of doing this? because i tried using fopen to open the files but for some reason when i do this it doesnt recognize (as you mentioned) the finalData, w hich is why I changed it to load.
Thank you so much and have a nice day :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by