divide data to 100 input files

10 ビュー (過去 30 日間)
Holden Caulfield
Holden Caulfield 2016 年 5 月 16 日
コメント済み: Walter Roberson 2016 年 5 月 17 日
I have a numeric data set as a 1xn (for example 1x32768) matrix, and I want to divide it into m files (for example 100 files) and making directories and send each file to corresponding directory. I did use the following code: reshape(Data,[],100); but problem is 32768 is not divisible to 100. is there any way for solve my issue? or I have to reduce my data to 32700? Any help is appreciated.
  3 件のコメント
Holden Caulfield
Holden Caulfield 2016 年 5 月 17 日
They're part of my data, actually it is part of an assignment, so I have to compute mean, variance and mean standard deviation of each data sets. And write them in a file. So I wonder there is a way to avoid data loss.
Walter Roberson
Walter Roberson 2016 年 5 月 17 日
If you need to do this for each data set, why are you grouping them into 100's ?

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

回答 (2 件)

Aritra Sasmal
Aritra Sasmal 2016 年 5 月 16 日
編集済み: Walter Roberson 2016 年 5 月 16 日
I don't understand why you want to reshape it but here's how you'd do it if you wanted to form a matrix like you have;
n=size(Data,1);
Mat=zeros(100,ceil(n/100));
Mat(:,1:floor(n/100))=reshape(Data(1:floor(n/100)),[],100);
Mat(1:(n%100),end)=Data(floor(n/100)+1:end);
This would create the 100 row matrix that you want.
However, you can just write a loop
i=1:ceil(n/100)
put stuff in an array and save as ascii file and close the filw pointer
end
This would package the data into smaller files in a loop
  2 件のコメント
Holden Caulfield
Holden Caulfield 2016 年 5 月 17 日
Thank for your help! But I believe reshape will create a matrix with 100 column, but your code supposed to create a matrix with 100 rows. Am I correct?
Walter Roberson
Walter Roberson 2016 年 5 月 17 日
The code Aritra posted does have a conflict between 100 rows and 100 columns.

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


Walter Roberson
Walter Roberson 2016 年 5 月 16 日
For numeric row matrix M,
block = 100;
blocked = mat2cell(M, 1, [block * ones(1, floor(M/block)), mod(M, block)]);
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 5 月 17 日
If you have a numeric matrix you want to rearrange into groups of fixed size, see buffer()

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by