.mat file size keeping it small on compiling
조회 수: 2 (최근 30일)
이전 댓글 표시
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![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/316338/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/316338/image.jpeg)
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
Walter Roberson
2020년 6월 29일
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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!