필터 지우기
필터 지우기

Concatenate more than 2 mat files?

조회 수: 2 (최근 30일)
Kaushik
Kaushik 2013년 5월 22일
Hi, I have 3 mat files which I want to concatenate. The three files may contain similar data variables or different data variables. The values of similar data variables should be concatenated and unique variables should be taken directly. This data should be saved in a new mat file. Can anyone suggest me how to do this. I tried the solution given at link http://www.mathworks.in/matlabcentral/answers/26949. But the solution given at above link is for similar data variables in both the files. Things get messy while concatenating 3 mat files with some data variables unique to only one, or some data variables present in only two mat files. Thus taking common from all the three files does not satisfy the requirements.
  댓글 수: 1
José-Luis
José-Luis 2013년 5월 22일
An example would be more helpful to understand what you ask. Have you tried cell arrays?

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 22일
You can load all your mat-files then concatenate whatever you want

Iain
Iain 2013년 5월 22일
편집: Iain 2013년 5월 22일
You need to load your mat files into variables. File1 = load('filename.mat');
File1 then contains the contents of filename. You need to interrogate that structure to get the list of variable names.
Then, you can make decisions about how to concatenate your files based on the variable names that are common to at least two of your input files.
To then put each of those back into the workspace you'll need to use "eval" to create the right variables in your workspace. - I would suggest you consider using a format other than mat for your input.
  댓글 수: 3
Iain
Iain 2013년 5월 22일
To save the concatenated values back out to file, you will need to make those variables appear in the workspace. You'll need to use something like
eval([variablename ' = [matfile1.' variablename ' matfile2.' variablename ' matfile3.' variablename '];');
But that will throw errors if "variablename" isn't in all of the matfiles, and if there are dimension mismatches...
Kaushik
Kaushik 2013년 5월 22일
yes, that's the problem. I could take out the variables that are common in all the 3 mat files, and unique between all the 3 mat files. But, what about the variables that are common to only 2 files? The code works fine if the variables are not common. or if there are only 2 mat files.

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

카테고리

Help CenterFile 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!

Translated by