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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by