How to zip mat files if they are less than a certain size in a folder?

6 ビュー (過去 30 日間)
Luna
Luna 2020 年 3 月 12 日
編集済み: Ameer Hamza 2020 年 3 月 16 日
Hello Dear Community,
I have a folder and I have a lot of mat files in it. Each mat file contains a struct with fields:
name.signals.values
name.signals.dimensions
name.Channelname
name.Channeltype
name.unit
name.timeunit
name.period
name.device
name.time
name.min
name.max
I have more than 300 names for each file. Depending on name.signals.values length, the file sizes change (from 0 to 300 MB). I want to compress those but after compression, the total size of each zip files should not exceed 3 GB. How can I do it? Do you have any ideas?
(Note that I don't want to split to volumes like partially compression.)
  1 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 3 月 16 日
.mat files are compressed by default. you are unlikely to be able to compress them very much.

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 3 月 16 日
編集済み: Ameer Hamza 2020 年 3 月 16 日
Try something like this
files = dir('*.mat');
MAX_SIZE = 2.9*2^30; % A bit less than 3GB, to allow for overhead of zip file
[sizes, size_order] = sort([files.bytes]);
file_no = find(cumsum(sizes) > MAX_SIZE, 1);
size_order(file_no:end) = [];
selected_files = files(size_order);
zip('filename', {selected_files.name});
This code read the name and size of all mat files and sort them by sizes. Then zip the files that add up to 3GB starting from the smallest file. I set the MAX_SIZE a bit less than 3GB because mat files are already quite compressed, the zip file cannot compress the further, but it adds a bit of its own overhead.

カテゴリ

Help Center および File ExchangeScope Variables and Generate Names についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by