Store several output matrices in a single matrix
4 views (last 30 days)
I have 205 .mat files of size 31590x6 and I have a script that takes the averages every 15 minutes so that every file is reduced to a size 34x6. So my main goal after calculating the 15 min intervals is to put all these reduced files into a single matrix that I can use later for other calculations.
The following script does the interval calculations without problems, but when I triy to put all the Oupt matrices of each file in a single matrix, it doesnt work :( because matlab says : ??? Index exceeds matrix dimensions.
file=dataFiles(d).name; %gets names of all mat files
%NAME DATE, STOCK AND TIMESTAMP
%NAME BID VARIABLES
%NAME ASK VARIABLES
%NAME BID VOLUME
%NAME ASK VOLUME
%CONVERT TIME STAMP AND DATE INTO NUMERIC VALUE
%CALCULATE TIME INTERVALS
t = dateNum+timeNum;
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
differences=zeros(size(t)); %assign memory
differences = timeNum(:)-firsttimestamp(:);
%CALCULATE BID MEANS
%CALCULATE ASK MEANS
%CALCULATE BID VOL MEANS
%CALCULATE ASK VOL MEANS
%CALCULATE TIME INTERVAL FOR TIME
%GET FIRST 34 NUMERIC VALUES OF DATE
%COLLECT OUTPUT IN MATRIX
%Outtput=[getdatenum timeinterval b1 a1 bv1 av1];
%STORE OUTPUT IN A MATRIX
Output=[getdatenum timeinterval b1 a1 bv1 av1];
Output=[getdatenum timeinterval b1 a1 bv1 av1];%i try w/4 var
The error I get is the following :??? Index exceeds matrix dimensions. And when i check the All_Data matrix it just contains one matrix of size 34x6, but i cant tell if it is the first matrix or the last one when the scripts runs the part of calculating the time intervals for all those 205 files.
So in the end, the last part of the code is trying to get a matrix of size 6970x6; composed of the output matrices of all the reduced files.
Do you see something wrong in the code? I don´t understand what the problem is and I have been trying it so many times that i don´t k now what else to do.
I would apprecciate any help.
Thank you and have a nice day!
Fangjun Jiang on 17 May 2011
You have a nested for-loop. You don't need the inner for-loop for this purpose.
You have the variable "All_Data" set to be empty at the beginning. You go through a loop for 205 files. Every loop you calculate the variable "Output" and then you append it to "All_Data". Your coding flow is sound.
Your code should work if you remove your inner for-loop. Just leave the line "All_Data=[All_Data;Output];" there.
A couple of advice: Don't use variable "date". It is a built-in function. Don't use confusing variable names like "All_Data" and then "All_data". In this case, "All_data" is never used. I believe it is a mistake. Remove it.