split array to subarray and save it as csv file
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have a csv file 6 x1086 I want to split it to 181 csv files each files 6x6 and save those files.
the first csv file will have the first 6 columns 1:6 , the second csv file will have the second 6 columns i.e. 7:12 ...etc.
I want to give name for each csv file for example: result1.csv , result2.csv ,...,result181.csv
Can you please help me with that. Thanks in advance
0 件のコメント
採用された回答
Voss
2023 年 3 月 7 日
fn = 'your\csv\file.csv';
pn = 'folder\where\you\want\the\results\to\go';
n = 6;
C = readcell(fn);
for ii = 1:size(C,2)/n
writecell(C(:,(ii-1)*n+(1:n)),fullfile(pn,sprintf('result%d.csv',ii)));
end
6 件のコメント
Voss
2023 年 3 月 8 日
n = 230;
m = 20;
for ii = 1:(size(C,2)-n)/m+1
writecell(C(:,(ii-1)*m+(1:n)),fullfile(pn,sprintf('result%d.csv',ii)));
end
This will give you 189 sub-matrices: C(:,1:230), C(21:250), C(41:270), ..., C(3741:3970), C(3761:3990)
(3761-1)/20+1 = 189
And the last one ends with 3990 not 4005, i.e., the last 15 columns of C will be left over.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!