Concatenating 'mat' files into a single file

Hi. I have 6 mat files with file names A,B,C,D,E,F each of size 1X36. Now I want to concatenate all this mat files(order same as above) in to new mat file that should be of size 1X216. Please help me in this regard...
Thanks,
srikanth

댓글 수: 3

Jos (10584)
Jos (10584) 2013년 2월 11일
I think you are confusing mat files and variables ...
srikanth
srikanth 2013년 2월 11일
no i mean '.mat' files. File names are A.mat,B.mat,C.mat,D.mat,E.mat,F.mat Each file contains some image information and of size {1x36} . Now i want to club all of them into single .mat file and make it as {1x216}. [ i.e 36*6=216]
José-Luis
José-Luis 2013년 2월 11일
Then you need to load them, concatenate the variables you want and save the result. You cannot simply concatenate mat files.

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2013년 2월 11일
편집: Jan 2013년 2월 11일

4 개 추천

The size of a MAT file is not exactly correlated to the size of the included data, because MAT files can be compressed and they have a header. Therefore it is unlikely, that joining the contents of 6 Matlab files leads to a MAT file, whose size is the sum of the single files. And concatenating the files directly will not work also.
I assume Jos is right: The size of MAT files is measured in Bytes, while an expression like "{1x36}" implies, that you are talking of a vector. Do you mean, that the contents of the MAT files are [1x36] double vectors?
FileList = {'A', 'B', 'C', 'D', 'E', 'F'};
Value = [];
for iFile = 1:numel(FileList)
Data = load([FileList{iFile}, '.mat']);
Field = struct2cell(Data);
if length(Field) ~= 1
error('Unexpected contents of [%s]', FileList{iFile});
end
Value = cat(2, Value, Field{1});
end
save('Joined.mat', 'Value');
If this does not help, please explain, what you actually want to combine.

댓글 수: 4

Sruthi D
Sruthi D 2019년 10월 14일
If the mat files are of differenet dimensions then how to concatenate.
Example: A.mat contains 165x14 , B.mat contains 169x14, C.mat contains 55x13 then how to concatenate them and save in one new .mat file?
Walter Roberson
Walter Roberson 2019년 10월 14일
What would you want as the result? A single .mat file with three variables? A single .mat file with a single variable that is a struct with one field per file? A single .mat file with a single variable that is (for example) [A; B; [C, nan(55,1)]] so as to pad C out to 55 x 14 so it could be put at the bottom of A and B ?
Sruthi D
Sruthi D 2019년 10월 14일
I need a single mat file with dimension 389x14
Walter Roberson
Walter Roberson 2019년 10월 15일
What do you want as the 14th column for the block that corresponds to C ?

댓글을 달려면 로그인하십시오.

Thorsten
Thorsten 2013년 2월 11일

0 개 추천

First load the file, assuming that each file contains a variable same as its filename, so after load A you have variable A in your workspace
load A
load B
load C
load D
load E
load F
Concatenate
X = [ A B C D E F];
Save to new mat file
save('X.mat', 'X')

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2013년 2월 11일

댓글:

2019년 10월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by