Unzip to a cell array, get the csv filles

1 回表示 (過去 30 日間)
CSCh
CSCh 2025 年 3 月 10 日
回答済み: CSCh 2025 年 3 月 11 日
HI I unzip a file to a cell
unzipfile =
10×1 cell array
{'2025-01-28/' }
{'2025-01-28/KBIS_V06_20250128_000621.csv'}
{'2025-01-28/KBIS_V06_20250128_001320.csv'}
{'2025-01-28/KBIS_V06_20250128_002007.csv'}
{'2025-01-28/KBIS_V06_20250128_002713.csv'}
{'2025-01-28/KBIS_V06_20250128_003412.csv'}
{'2025-01-28/KBIS_V06_20250128_004111.csv'}
{'2025-01-28/KBIS_V06_20250128_004816.csv'}
{'2025-01-28/KBIS_V06_20250128_005509.csv'}
{'2025-01-28/KBIS_V06_20250128_010208.csv'}
}
How can I get the content of the csv files? I woul like to avoid use unzip command to a folder I need a fast solution becaus I have lots of zip files containing hundrets of csv.

採用された回答

Stephen23
Stephen23 2025 年 3 月 11 日
編集済み: Stephen23 2025 年 3 月 11 日
"I got Error using readtable Unable to find or open '2025-01-28/'. Check the path and filename or file permissions."
You get an error because a folder is not a file, yet you are trying to call FOPEN/READTABLE on a folder (the CSV files are stored in a folder, which UNZIP returns as the first element of the output cell array). Use ISFILE or similar to ignore any folders:
P = './mysub'; % absolute/relative path to where the files are unzipped to
C = unzip('2025-03-11.zip',P) % note the first element is NOT a filename!
C = 1x4 cell array
{'./mysub/2025-03-11/'} {'./mysub/2025-03-11/KBIS_1.csv'} {'./mysub/2025-03-11/KBIS_2.csv'} {'./mysub/2025-03-11/KBIS_3.csv'}
dir(C{1})
. .. KBIS_1.csv KBIS_2.csv KBIS_3.csv
C(~cellfun(@isfile,C)) = []; % remove folder names
D = C;
for k = 1:numel(C)
F = C{k};
T = readtable(F);
D{k} = T;
end
All of the imported data is in the cell array D
D{:}
ans = 1x3 table
X Y Z _ _ _ 1 2 3
ans = 1x3 table
X Y Z _ _ _ 4 5 6
ans = 1x3 table
X Y Z _ _ _ 7 8 9
vertcat(D{:})
ans = 3x3 table
X Y Z _ _ _ 1 2 3 4 5 6 7 8 9
Depending on the existence of other files, you might also be able to use DIR.

その他の回答 (2 件)

Diego Caro
Diego Caro 2025 年 3 月 10 日
Use readmatrix for each cell. Use a for loop.

CSCh
CSCh 2025 年 3 月 11 日
Thank you so much, Steven and Walter. Both codes work. However, I guess a more "memory-friendly" (without unpacking to folder + loop) alternative is not feasbe, right?

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by