0

I have a large column of data (400,000+ data points) being imported from a text file. I need the column to be divided into multiple columns of length 7,000. It is already in order, so the first 7,000 data points would stay in the first column, the next 7,000 would go to the next column, and so forth...

Prefoninsane
  • 103
  • 1
  • 11

3 Answers3

3

You can reshape the data into a 2D matrix, but all columns must be the same length (7,000).

You can either select only complete columns:

x = rand(1,400000);    
N = 7000;
cols = floor(length(x)/N);
y = reshape(x(1:N*cols), [N,cols]);

Alternatively, you can pad the final column (eg with zeros):

x = rand(1,400000);    
N = 7000;
cols = ceil(length(x)/N);
y = zeros(N, cols);
y(1:length(x)) = x;
smn
  • 548
  • 2
  • 7
2

Use buffer command:

x = rand(400000,1);
[out,z]=buffer(x,7000);

Here out corresponds to the 2D matrix with 7000 elements in each column. If the length of the vector is not divisible by 7000, the last column of data which has length less than 7000 is stored in z.

Naveen
  • 306
  • 1
  • 6
1

Using reshape function can do this

A = reshape(B,7000,[]);
Prefoninsane
  • 103
  • 1
  • 11
  • 1
    You have chosen to write your own answer. As such, either accept your own answer to signify the SO community that you no longer need help, or accept one of the answers above. – rayryeng Jul 10 '14 at 16:36
  • Per SO rules, you must wait 48 hours from the time you originally asked your question before you can accept your own answer. So simmer down rayryeng, I will get to it when the time comes – Prefoninsane Jul 10 '14 at 18:34
  • Sorry, I forgot there was a 48 hour limit. Not sure why you told me to simmer down as I wasn't angry. Just want to make sure that people know this question is solved. On the other hand, you could go ahead and accept any of the other answers to give them some rep points :) You don't get anything by accepting your own answer. – rayryeng Jul 10 '14 at 22:56