0
votes

I have already looked at previous posts but can't find a satisfactory solution to my case yet. I am new to Matlab and have input/output device data which i have arranged into column vectors, now i need to loop equal sized windows through the whole datafile by creating same sized vectors at each instance. The data has 600 columns as example table below. Sorry it doesnt look the best as it won't allow me to edit it properly: All vectors i2, i3, i4,...,i600 are built exactly the same way as i1.

Data type ____ Columns 1 … 600

Input

         0.20    0.37   0.21   -0.04    …

        -0.06    0.01   0.31    0.17   ...

Output

         0.34   -0.08   0.59    -0.04   …
         0.11    0.06   0.72     0.18   …
        -0.27    0.09   0.59     0.03   …

Each vector would have 14 elements from the data. So i1=[0.20; -0.06; 0.37; 0.01; 0.21; 0.31; -0.04; 0.17;...], i2=[0.37; 0.01; 0.21; 0.31; -0.04; 0.17;...], i3=[0.21; 0.31; -0.04; 0.17;...],..to i600. It means essentially vector i1 will be built by input data values in columns 1-7 as listed, and i2 will contain columns 2-8, while i3 columns 3-9 and so forth. As you can see, hence am trying to create data by forming 'overlapping' 14x1 input vectors. The outputs ie o1, o2,..will also be formed in exactly the same way only that vectors will be 21x1 in size, how do i build these vectors from this data? I am now stuck please help,

Thank you in advance :) Tee

1
It's not really clear why you'd want to do that instead of the simpler option of reading the whole lot into one big matrix, then splitting it as needed. As always, the documentation is a good place to start.Notlikethat
Thanks for your reply. I already imported the device data into text format as above. I want to build input and output vectors so i can utilise them in an equation. Use every 7 consecutive elements to create a vector and do this slipping through the entire data and then visualise the combined structure at the end. So in short i want to split I (input data) into vectors i1, i2i, i3,..i600 (each of 14x1 sizes) and do the same for O (output data) of vector sizes 21x1. As this is a relatively large datafile, how best can i do this? Thankstgirl4me
Can't you just read it into a a single vector and then use reshape to change it to a 14xN array. Then you can rather simply pick off whatever combination of columns you want.AnonSubmitter85
Thanks for the suggestion AnonSubmitter85 however with my little Matlab experience i suspect reshape will only allow me to change the dimensions of the array is this correct? Maybe i wasnt very clear. What i want to be able to do is create 14x 1 vectors with data say i1 matrix vector from columns 1-7, i2 with columns 2-8, i3 with columns 3-9 etc up to i600. Cheerstgirl4me
It's still not clear to me what you are trying to do. Could you edit your question with an example of what I2, I3, ... are? Currently you only show what I1 is.AnonSubmitter85

1 Answers

0
votes
% Make a 2x600 array with random entries.
Q = rand( 2, 600 );

% The offset for the beginning of each
% set we want to extract from the above
% array. We subtract 7 from 600 since we are
% pulling off 14 elements at a time and thus
% have to stop at the 7th-to-last column.
offsets = 2 * ( 0 : 600 - 7 );

% These are indices of the elements we want
% organized by column. All we have to do is
% offset the numbers 1 thorugh 14 by the 
% amounts found above.
v = (1:14)';
inds = repmat( v, 1, length( offsets ) ) + repmat( offsets, length(v), 1 );

% Now we can pull off the overlapping submatrices we want.
C = Q(inds);

Here is some example output:

>> Q(:,1:10)

ans =

    0.8147    0.1270    0.6324    0.2785    0.9575    0.1576    0.9572    0.8003    0.4218    0.7922
    0.9058    0.9134    0.0975    0.5469    0.9649    0.9706    0.4854    0.1419    0.9157    0.9595

>> C(:,1:2)

ans =

    0.8147    0.1270
    0.9058    0.9134
    0.1270    0.6324
    0.9134    0.0975
    0.6324    0.2785
    0.0975    0.5469
    0.2785    0.9575
    0.5469    0.9649
    0.9575    0.1576
    0.9649    0.9706
    0.1576    0.9572
    0.9706    0.4854
    0.9572    0.8003
    0.4854    0.1419

You can see that first row of C is the first 7 columns of Q, while its second column are columns 2-8 of Q.