필터 지우기
필터 지우기

Export rows as combined separate CSV files

조회 수: 2 (최근 30일)
Aero Descerazes
Aero Descerazes 2022년 6월 16일
답변: Peter Perkins 2022년 6월 17일
Hi I have a 255 x 3 cell array that looks like shown below. I want to export all the column values from each row as tables in CSV files. In this case this will result in 255 CSV files with 1024 x 3 tables.
Thanks in advance!

답변 (1개)

Peter Perkins
Peter Perkins 2022년 6월 17일
There are a bunch of ways to do this. I thought I'd see how well rowfun works:
> C = {rand(10,1) rand(10,1); rand(10,1) rand(10,1); rand(10,1) rand(10,1)}
C =
3×2 cell array
{10×1 double} {10×1 double}
{10×1 double} {10×1 double}
{10×1 double} {10×1 double}
Turn that cell array into a table with two cell variables:
>> T = cell2table(C)
T =
3×2 table
C1 C2
_____________ _____________
{10×1 double} {10×1 double}
{10×1 double} {10×1 double}
{10×1 double} {10×1 double}
Combine the two col vectors in each row of T to make a table containing one cell variable, each cell containing a table, Then add a file name to each row:
>> T = rowfun(@(c1,c2) {table(c1,c2)},T,"ExtractCellContents",true)
T =
3×1 table
Var1
____________
{10×2 table}
{10×2 table}
{10×2 table}
>> T.Name = "data" + (1:3)' + ".csv"
T =
3×2 table
Var1 Name
____________ ___________
{10×2 table} "data1.csv"
{10×2 table} "data2.csv"
{10×2 table} "data3.csv"
Now use rowfun to write out each table:
>> rowfun(@(c,name) writetable(c{:},name),T,"NumOutputs",0);

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by