zenab
zenab

Reputation: 229

Merge data of one variable in matlab with another variable in another mat file in matlab

I have 2 mat files , I would like to merge these files by adding all the records from file1 to the end of file 2, I would like to inform you that these files include the same varaible as:

mat file1 include (100) records :

file name distance value

mat file2 include (800) records:

file name distance value

I want to get the file2 with 1000 records is it possible in matlab or not?

Upvotes: 1

Views: 1435

Answers (1)

jpjacobs
jpjacobs

Reputation: 9549

Updated version

So apparently you've got this in your files:

myStruct = struct('Names', cell(n,1), 'Distances', []);

Where all arrays (cell and normal matrices) contain the different samples in the rows.

You'll be doing something like:

struct1=load('file1.mat');
struct2=load('file2.mat');

struct2.myStruct.Names=[struct2.myStruct.Names;struct1.myStruct.Names];
struct2.myStruct.Distances=[struct2.myStruct.Distances;struct1.myStruct.Distances];
save('file2.mat','-struct',struct2);

Upvotes: 3

Related Questions