Appending two or more .mat files
Afficher commentaires plus anciens
Hi
I have two .mat files ECU_1.mat and ECU_2.mat (basically both files contains same variables in level 1, of ECU_1.mat and ECU_2.mat, and the corresponding readings in level 2). I need to create a new ECU_A.mat file that would append both the .mat files into ECU_A.mat files and have all the level 1 and level 2 in the same way but with additional data of ECU_2.mat.
Thanks Ferd
Réponse acceptée
Plus de réponses (2)
Thomas
le 24 Jan 2012
load both the *.mat files with the variables, append them in matlab and save them using save command
load ECU_A.mat % suppose this has variables a & b
load ECU_B.mat % suppose this has variables c & d
% assuming all variables of the same length and are corresponding
new_data=[a b c d] % if you need them in a single matrix
save ECU_A.mat
3 commentaires
Ferd
le 24 Jan 2012
Thomas
le 24 Jan 2012
If the variable from both mat files has the same name, you need to rename them after you load the first mat file otherwise they will be overwritten in the variable space.
then you can load the second mat file and append it to the bottom of the first.
example if you have the four variables a,b,a1 and b1 in your workspace and you want to append a1 underneath a and b1 underneath b you would use some thing like:
load ECU_A.mat % suppose this has variables a & b
load ECU_B.mat % suppose this has variables a1 & b1
c=[a;a1];
d=[b;b1];
new_data=[c d]
Ferd
le 24 Jan 2012
C.J. Harris
le 28 Mar 2012
You can also load data into a structure, and manipulate it from there. For example:
FILE_A = load('ECU_1.mat');
FILE_B = load('ECU_2.mat');
Then if a variable exists in both you could join them in any way you like:
A_COMBINED = [FILE_A.A; FILE_B.A];
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!