.mat file size keeping it small on compiling

1 view (last 30 days)
Hi,
I'm compiling some .mat files and saving it, but the overall saved data is bigger than the sumer of the files being used.
Is this normal? Is there a way to keep it down?
The compiled file is 470MB, and the sum of the files being used is about 125MB
form=1; %make sure to also change the formulation number under filename
scenarios = 5;
Nscen = numel(scenarios);
IDsets = 1:500:3001;
NID = numel(IDsets);
filedir = 'Outputs';
indvoutputagg = cell(NID,1); % preallocate
indvoutputcomp={};
for i=1:Nscen
for k = 1:NID
filename = sprintf('Form1_Scenario%d_ID%ds_indvoutputagg.mat',scenarios(i),IDsets(k));
indvoutputagg{k,:} = importdata(fullfile(filedir,filename)); % allocate using indexing
% Make it into one big table
indvoutputcomp(1+size(indvoutputcomp,1):size(indvoutputcomp,1)+size(indvoutputagg{k,1},1),:)=indvoutputagg{k};
end
save(['Outputs/Form' num2str(form) '_Scenario' num2str(scenarios(i)) '_indvoutputagg.mat'],'indvoutputcomp')
end
  5 Comments
In-chan Kim
In-chan Kim on 29 Jun 2020
Is there something I can do to make it smaller?
Walter Roberson
Walter Roberson on 29 Jun 2020
I recommend against using importdata() -- too much overhead for the cases where the output is well defined, and too uncertain about what it will return for the other cases. You are reading in a .mat file: just load() it .
The .mat files you are reading in: do they all have exactly the same variable names? Would the variable names also happen to be in exactly the same order in each file? If they do not have exactly the same variable names, then are the variable names self-identifying as to which file they came from? For example if all of the 501 variables mention 501 at a particular location in their name, then if we threw all the loaded variables into the same structure, we could figure out afterwards which file they came from.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!